Logging : Renamed DbgPrintf to DBG_PRINTF (it's a macro after all), introduced Ex-tended versions of a few macro's, which accept something else than LOG_PREFIX and removed and/or applied LOG_PREFIX where appropriate. Also applied LOG_CHECK_ENABLED in EmuX86 to avoid slowdowns when X86 debug logging is disabled.

This commit is contained in:
PatrickvL 2018-09-24 11:26:30 +02:00
parent ac719e2a40
commit 17fdc8e01d
36 changed files with 1213 additions and 1203 deletions

View File

@ -46,7 +46,7 @@ namespace xboxkrnl
#include <stdio.h> // For printf
#include <shlobj.h> // For HANDLE, CreateFile, CreateFileMapping, MapViewOfFile
#include "Cxbx.h" // For DbgPrintf
#include "Cxbx.h" // For DBG_PRINTF_EX
#include "EmuEEPROM.h" // For EEPROMInfo, EEPROMInfos
#include "..\CxbxKrnl\Emu.h" // For EmuWarning
#include "..\..\src\devices\LED.h" // For SetLEDSequence
@ -130,7 +130,7 @@ xboxkrnl::XBOX_EEPROM *CxbxRestoreEEPROM(char *szFilePath_EEPROM_bin)
/* hTemplateFile */nullptr);
if (hFileEEPROM == INVALID_HANDLE_VALUE)
{
DbgPrintf(LOG_PREFIX_INIT, "Couldn't create EEPROM.bin file!\n");
DBG_PRINTF_EX(LOG_PREFIX_INIT, "Couldn't create EEPROM.bin file!\n");
return nullptr;
}
}
@ -148,7 +148,7 @@ xboxkrnl::XBOX_EEPROM *CxbxRestoreEEPROM(char *szFilePath_EEPROM_bin)
/**/nullptr);
if (hFileMappingEEPROM == NULL)
{
DbgPrintf(LOG_PREFIX_INIT, "Couldn't create EEPROM.bin file mapping!\n");
DBG_PRINTF_EX(LOG_PREFIX_INIT, "Couldn't create EEPROM.bin file mapping!\n");
return nullptr;
}
@ -169,7 +169,7 @@ xboxkrnl::XBOX_EEPROM *CxbxRestoreEEPROM(char *szFilePath_EEPROM_bin)
/* dwFileOffsetLow */0,
EEPROM_SIZE);
if (pEEPROM == nullptr) {
DbgPrintf(LOG_PREFIX_INIT, "Couldn't map EEPROM.bin into memory!\n");
DBG_PRINTF_EX(LOG_PREFIX_INIT, "Couldn't map EEPROM.bin into memory!\n");
return nullptr;
}
@ -185,12 +185,12 @@ xboxkrnl::XBOX_EEPROM *CxbxRestoreEEPROM(char *szFilePath_EEPROM_bin)
// This must be done last to include all initialized data in the CRC
gen_section_CRCs(pEEPROM);
DbgPrintf(LOG_PREFIX_INIT, "Initialized default EEPROM\n");
DBG_PRINTF_EX(LOG_PREFIX_INIT, "Initialized default EEPROM\n");
}
else
{
XboxFactoryGameRegion = pEEPROM->EncryptedSettings.GameRegion;
DbgPrintf(LOG_PREFIX_INIT, "Loaded EEPROM.bin\n");
DBG_PRINTF_EX(LOG_PREFIX_INIT, "Loaded EEPROM.bin\n");
}
// Read the HDD (and eventually also the online) keys stored in the eeprom file. Users can input them in the eeprom menu

View File

@ -52,7 +52,7 @@ typedef enum class _LOG_LEVEL {
}LOG_LEVEL;
typedef enum class _CXBXR_MODULE: unsigned int {
// general
// general
CXBXR = 0,
XBE,
INIT,
@ -112,7 +112,7 @@ typedef enum class _CXBXR_MODULE: unsigned int {
XC,
XE,
// max
MAX,
MAX,
}CXBXR_MODULE;
extern std::atomic_bool g_EnabledModules[to_underlying(CXBXR_MODULE::MAX)];
@ -256,9 +256,13 @@ constexpr const char* remove_emupatch_prefix(const char* str) {
extern thread_local std::string _logThreadPrefix;
// Checks if this log should be printed or not
#define LOG_CHECK_ENABLED(cxbxr_module, level) \
#define LOG_CHECK_ENABLED_EX(cxbxr_module, level) \
if (g_EnabledModules[to_underlying(cxbxr_module)] && to_underlying(level) >= g_CurrentLogLevel)
// Checks if this log should be printed or not
#define LOG_CHECK_ENABLED(level) \
LOG_CHECK_ENABLED_EX(LOG_PREFIX, level)
#define LOG_THREAD_INIT \
if (_logThreadPrefix.length() == 0) { \
std::stringstream tmp; \
@ -289,7 +293,7 @@ extern thread_local std::string _logThreadPrefix;
#define LOG_FUNC_BEGIN \
LOG_INIT \
LOG_CHECK_ENABLED(LOG_PREFIX, LOG_LEVEL::DEBUG) { \
LOG_CHECK_ENABLED(LOG_LEVEL::DEBUG) { \
LOG_FUNC_BEGIN_NO_INIT
// LOG_FUNC_ARG writes output via all available ostream << operator overloads, sanitizing and adding detail where possible
@ -326,7 +330,7 @@ extern thread_local std::string _logThreadPrefix;
// LOG_FORWARD indicates that an api is implemented by a forward to another API
#define LOG_FORWARD(api) \
LOG_INIT \
LOG_CHECK_ENABLED(LOG_PREFIX, LOG_LEVEL::DEBUG) { \
LOG_CHECK_ENABLED(LOG_LEVEL::DEBUG) { \
do { if(g_bPrintfOn) { \
std::cout << _logThreadPrefix << _logFuncPrefix << " forwarding to "#api"...\n"; \
} } while (0); \
@ -337,7 +341,7 @@ extern thread_local std::string _logThreadPrefix;
do { \
static bool b_echoOnce = true; \
if(g_bPrintfOn && b_echoOnce) { \
LOG_CHECK_ENABLED(LOG_PREFIX, LOG_LEVEL::INFO) { \
LOG_CHECK_ENABLED(LOG_LEVEL::INFO) { \
LOG_THREAD_INIT \
LOG_FUNC_INIT(__func__) \
std::cout << _logThreadPrefix << "WARN: " << _logFuncPrefix << " ignored!\n"; \
@ -351,7 +355,7 @@ extern thread_local std::string _logThreadPrefix;
do { \
static bool b_echoOnce = true; \
if(g_bPrintfOn && b_echoOnce) { \
LOG_CHECK_ENABLED(LOG_PREFIX, LOG_LEVEL::INFO) { \
LOG_CHECK_ENABLED(LOG_LEVEL::INFO) { \
LOG_THREAD_INIT \
LOG_FUNC_INIT(__func__) \
std::cout << _logThreadPrefix << "WARN: " << _logFuncPrefix << " unimplemented!\n"; \
@ -365,7 +369,7 @@ extern thread_local std::string _logThreadPrefix;
do { \
static bool b_echoOnce = true; \
if(g_bPrintfOn && b_echoOnce) { \
LOG_CHECK_ENABLED(LOG_PREFIX, LOG_LEVEL::INFO) { \
LOG_CHECK_ENABLED(LOG_LEVEL::INFO) { \
LOG_THREAD_INIT \
LOG_FUNC_INIT(__func__) \
std::cout << _logThreadPrefix << "WARN: " << _logFuncPrefix << " incomplete!\n"; \
@ -379,7 +383,7 @@ extern thread_local std::string _logThreadPrefix;
do { \
static bool b_echoOnce = true; \
if(g_bPrintfOn && b_echoOnce) { \
LOG_CHECK_ENABLED(LOG_PREFIX, LOG_LEVEL::INFO) { \
LOG_CHECK_ENABLED(LOG_LEVEL::INFO) { \
LOG_THREAD_INIT \
LOG_FUNC_INIT(__func__) \
std::cout << _logThreadPrefix << "WARN: " << _logFuncPrefix << " not supported!\n"; \
@ -393,13 +397,16 @@ extern thread_local std::string _logThreadPrefix;
#pragma warning(disable : 4477)
#endif
#define DbgPrintf(cxbxr_module, fmt, ...) { \
LOG_CHECK_ENABLED(cxbxr_module, LOG_LEVEL::DEBUG) { \
#define DBG_PRINTF_EX(cxbxr_module, fmt, ...) { \
LOG_CHECK_ENABLED_EX(cxbxr_module, LOG_LEVEL::DEBUG) { \
CXBX_CHECK_INTEGRITY(); \
if(g_bPrintfOn) printf("[0x%.4X] %s"##fmt, GetCurrentThreadId(), g_EnumModules2String[to_underlying(cxbxr_module)], ##__VA_ARGS__); \
} \
}
#define DBG_PRINTF(fmt, ...) \
DBG_PRINTF_EX(LOG_PREFIX, fmt, ##__VA_ARGS__)
#ifdef _MSC_VER
#pragma warning(pop)
#endif
@ -421,14 +428,14 @@ extern thread_local std::string _logThreadPrefix;
#define LOG_FUNC_ONE_ARG_OUT(arg) LOG_FUNC_BEGIN LOG_FUNC_ARG_OUT(arg) LOG_FUNC_END
// RETURN logs the given result and then returns it (so this should appear last in functions)
#define RETURN(r) do { if (g_bPrintfOn) LOG_CHECK_ENABLED(LOG_PREFIX, LOG_LEVEL::DEBUG) { LOG_FUNC_RESULT(r) } return r; } while (0)
#define RETURN(r) do { if (g_bPrintfOn) LOG_CHECK_ENABLED(LOG_LEVEL::DEBUG) { LOG_FUNC_RESULT(r) } return r; } while (0)
// RETURN_TYPE logs the given typed result and then returns it (so this should appear last in functions)
#define RETURN_TYPE(type, r) do { if (g_bPrintfOn) LOG_CHECK_ENABLED(LOG_PREFIX, LOG_LEVEL::DEBUG) { LOG_FUNC_RESULT_TYPE(type, r) } return r; } while (0)
#define RETURN_TYPE(type, r) do { if (g_bPrintfOn) LOG_CHECK_ENABLED(LOG_LEVEL::DEBUG) { LOG_FUNC_RESULT_TYPE(type, r) } return r; } while (0)
#define LOG_ONCE(msg, ...) { static bool bFirstTime = true; if(bFirstTime) { bFirstTime = false; DbgPrintf(LOG_PREFIX, "TRAC: " ## msg, __VA_ARGS__); } }
#define LOG_ONCE(msg, ...) { static bool bFirstTime = true; if(bFirstTime) { bFirstTime = false; DBG_PRINTF("TRAC: " ## msg, __VA_ARGS__); } }
#define LOG_XBOX_CALL(func) DbgPrintf(LOG_PREFIX, "TRAC: Xbox " ## func ## "() call\n");
#define LOG_XBOX_CALL(func) DBG_PRINTF("TRAC: Xbox " ## func ## "() call\n");
#define LOG_FIRST_XBOX_CALL(func) LOG_ONCE("First Xbox " ## func ## "() call\n");
//

View File

@ -122,7 +122,7 @@ extern bool g_SaveOnExit;
/*! maximum number of threads cxbx can handle */
#define MAXIMUM_XBOX_THREADS 256
/*! runtime DbgPrintf toggle boolean */
/*! runtime DBG_PRINTF toggle boolean */
extern volatile bool g_bPrintfOn;
#ifdef _MSC_VER

View File

@ -131,7 +131,7 @@ namespace xbdm {
void DmSendNotificationString(LPCSTR sz)
{
// Just send this string to Cxbx's debug output :
DbgPrintf(LOG_PREFIX, "%s\n", sz);
DBG_PRINTF("%s\n", sz);
}
// 0x0025 (37)

View File

@ -128,7 +128,7 @@ void WndMain::ResizeWindow(HWND hwnd, bool bForGUI)
const char* resolution = XBVideoConf.szVideoResolution;
if (2 != sscanf(resolution, "%d x %d", &m_w, &m_h)) {
DbgPrintf(LOG_PREFIX, "Couldn't parse resolution : %s.\n", resolution);
DBG_PRINTF("Couldn't parse resolution : %s.\n", resolution);
}
}

View File

@ -1433,7 +1433,7 @@ __declspec(noreturn) void CxbxKrnlInit
CxbxRegisterDeviceHostPath(DeviceHarddisk0Partition7, CxbxBasePath + "Partition7");
// Create default symbolic links :
DbgPrintf(LOG_PREFIX_INIT, "Creating default symbolic links.\n");
DBG_PRINTF_EX(LOG_PREFIX_INIT, "Creating default symbolic links.\n");
{
// TODO: DriveD should always point to the Xbe Path
// This is the only symbolic link the Xbox Kernel sets, the rest are set by the application, usually via XAPI.
@ -1497,7 +1497,7 @@ __declspec(noreturn) void CxbxKrnlInit
// Make sure the Xbox1 code runs on one core (as the box itself has only 1 CPU,
// this will better aproximate the environment with regard to multi-threading) :
DbgPrintf(LOG_PREFIX_INIT, "Determining CPU affinity.\n");
DBG_PRINTF_EX(LOG_PREFIX_INIT, "Determining CPU affinity.\n");
{
if (!GetProcessAffinityMask(g_CurrentProcessHandle, &g_CPUXbox, &g_CPUOthers))
CxbxKrnlCleanup(LOG_PREFIX_INIT, "GetProcessAffinityMask failed.");
@ -1516,7 +1516,7 @@ __declspec(noreturn) void CxbxKrnlInit
}
// initialize graphics
DbgPrintf(LOG_PREFIX_INIT, "Initializing render window.\n");
DBG_PRINTF_EX(LOG_PREFIX_INIT, "Initializing render window.\n");
XTL::CxbxInitWindow(true);
// Now process the boot flags to see if there are any special conditions to handle
@ -1567,7 +1567,7 @@ __declspec(noreturn) void CxbxKrnlInit
if (!bLLE_GPU)
{
DbgPrintf(LOG_PREFIX_INIT, "Initializing Direct3D.\n");
DBG_PRINTF_EX(LOG_PREFIX_INIT, "Initializing Direct3D.\n");
XTL::EmuD3DInit();
}
@ -1605,13 +1605,13 @@ __declspec(noreturn) void CxbxKrnlInit
DWORD dwThreadId;
HANDLE hThread = (HANDLE)_beginthreadex(NULL, NULL, CxbxKrnlInterruptThread, NULL, NULL, (uint*)&dwThreadId);
DbgPrintf(LOG_PREFIX_INIT, "Calling XBE entry point...\n");
DBG_PRINTF_EX(LOG_PREFIX_INIT, "Calling XBE entry point...\n");
CxbxLaunchXbe(Entry);
// FIXME: Wait for Cxbx to exit or error fatally
Sleep(INFINITE);
DbgPrintf(LOG_PREFIX_INIT, "XBE entry point returned\n");
DBG_PRINTF_EX(LOG_PREFIX_INIT, "XBE entry point returned\n");
fflush(stdout);
// EmuShared::Cleanup(); FIXME: commenting this line is a bad workaround for issue #617 (https://github.com/Cxbx-Reloaded/Cxbx-Reloaded/issues/617)
@ -1669,7 +1669,7 @@ __declspec(noreturn) void CxbxKrnlCleanup(CXBXR_MODULE cxbxr_module, const char
vsprintf(szBuffer2, szErrorMessage, argp);
va_end(argp);
CxbxPopupMessage(cxbxr_module, LOG_LEVEL::FATAL, CxbxMsgDlgIcon_Error, "Received Fatal Message:\n\n* %s\n", szBuffer2); // Will also DbgPrintf
CxbxPopupMessage(cxbxr_module, LOG_LEVEL::FATAL, CxbxMsgDlgIcon_Error, "Received Fatal Message:\n\n* %s\n", szBuffer2); // Will also DBG_PRINTF
}
printf("[0x%.4X] MAIN: Terminating Process\n", GetCurrentThreadId());

View File

@ -210,7 +210,7 @@ void CxbxPopupMessage(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, CxbxMsgDlgIcon
#define LOG_TEST_CASE(message) do { static bool bTestCaseLogged = false; \
if (!bTestCaseLogged) { bTestCaseLogged = true; \
LOG_CHECK_ENABLED(LOG_PREFIX, LOG_LEVEL::INFO) { \
LOG_CHECK_ENABLED(LOG_LEVEL::INFO) { \
CxbxPopupMessage(LOG_PREFIX, LOG_LEVEL::INFO, CxbxMsgDlgIcon_Info, "Please report that %s shows the following message:\nLOG_TEST_CASE: %s\nIn %s (%s line %d)", \
CxbxKrnl_Xbe->m_szAsciiTitle, message, __func__, __FILE__, __LINE__); } } } while (0)
// was g_pCertificate->wszTitleName

View File

@ -191,7 +191,7 @@ void DbgConsole::ParseCommand()
printf("CxbxDbg: Quit/Exit [Q] : Stop Emulation\n");
printf("CxbxDbg: Trace [T] : Toggle Debug Trace\n");
LOG_CHECK_ENABLED(CXBXR_MODULE::VTXB, LOG_LEVEL::DEBUG) {
LOG_CHECK_ENABLED_EX(CXBXR_MODULE::VTXB, LOG_LEVEL::DEBUG) {
printf("CxbxDbg: ListVB [LVB] : List Active Vertex Buffers\n");
printf("CxbxDbg: DisableVB [DVB #] : Disable Active Vertex Buffer(s)\n");
printf("CxbxDbg: EnableVB [EVB #] : Enable Active Vertex Buffer(s)\n");
@ -219,7 +219,7 @@ void DbgConsole::ParseCommand()
}
else if(_stricmp(szCmd, "lvb") == 0 || _stricmp(szCmd, "ListVB") == 0)
{
LOG_CHECK_ENABLED(CXBXR_MODULE::VTXB, LOG_LEVEL::DEBUG) {
LOG_CHECK_ENABLED_EX(CXBXR_MODULE::VTXB, LOG_LEVEL::DEBUG) {
int v = 0;
g_VBTrackTotal.Lock();
@ -240,7 +240,7 @@ void DbgConsole::ParseCommand()
}
else if(_stricmp(szCmd, "dvb") == 0 || _stricmp(szCmd, "DisableVB") == 0)
{
LOG_CHECK_ENABLED(CXBXR_MODULE::VTXB, LOG_LEVEL::DEBUG) {
LOG_CHECK_ENABLED_EX(CXBXR_MODULE::VTXB, LOG_LEVEL::DEBUG) {
int n = 0, m = 0;
int c = sscanf(m_szInput, "%*s %d-%d", &n, &m);
@ -261,7 +261,7 @@ void DbgConsole::ParseCommand()
}
else if(_stricmp(szCmd, "evb") == 0 || _stricmp(szCmd, "EnableVB") == 0)
{
LOG_CHECK_ENABLED(CXBXR_MODULE::VTXB, LOG_LEVEL::DEBUG) {
LOG_CHECK_ENABLED_EX(CXBXR_MODULE::VTXB, LOG_LEVEL::DEBUG) {
int n = 0, m = 0;
int c = sscanf(m_szInput, "%*s %d-%d", &n, &m);

View File

@ -114,7 +114,7 @@ void NTAPI EmuLog(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, const char *szWarn
return;
}
LOG_CHECK_ENABLED(cxbxr_module, level) {
LOG_CHECK_ENABLED_EX(cxbxr_module, level) {
if (g_bPrintfOn) {
va_list argp;

View File

@ -46,7 +46,7 @@ namespace xboxkrnl
#include "EmuKrnl.h" // For InitializeListHead(), etc.
#include "EmuFS.h"
#include "CxbxKrnl.h"
#include "VMManager.h"
#include "VMManager.h"
#include "Logging.h"
#undef FIELD_OFFSET // prevent macro redefinition warnings
@ -133,30 +133,30 @@ uint32_t fs_lock = 0;
__declspec(naked) void LockFS()
{
__asm {
pushfd
pushad
spinlock :
mov eax, 1
xchg eax, fs_lock
test eax, eax
jnz spinlock
popad
popfd
ret
__asm {
pushfd
pushad
spinlock :
mov eax, 1
xchg eax, fs_lock
test eax, eax
jnz spinlock
popad
popfd
ret
}
}
__declspec(naked) void UnlockFS()
{
__asm {
pushfd
pushad
xor eax, eax
xchg eax, fs_lock
popad
popfd
ret
__asm {
pushfd
pushad
xor eax, eax
xchg eax, fs_lock
popad
popfd
ret
}
}
@ -500,7 +500,7 @@ void EmuInitFS()
fsInstructions.push_back({ { 0x64, 0xA1, 0x58, 0x00, 0x00, 0x00 }, &EmuFS_MovEaxFs58 }); // mov eax, large fs:58
fsInstructions.push_back({ { 0x64, 0xA3, 0x00, 0x00, 0x00, 0x00 }, &EmuFS_MovFs00Eax }); // mov large fs:0, eax
DbgPrintf(CXBXR_MODULE::INIT, "Patching FS Register Accesses\n");
DBG_PRINTF_EX(CXBXR_MODULE::INIT, "Patching FS Register Accesses\n");
DWORD sizeOfImage = CxbxKrnl_XbeHeader->dwSizeofImage;
long numberOfInstructions = fsInstructions.size();
@ -510,7 +510,7 @@ void EmuInitFS()
continue;
}
DbgPrintf(CXBXR_MODULE::INIT, "Searching for FS Instruction in section %s\n", CxbxKrnl_Xbe->m_szSectionName[sectionIndex]);
DBG_PRINTF_EX(CXBXR_MODULE::INIT, "Searching for FS Instruction in section %s\n", CxbxKrnl_Xbe->m_szSectionName[sectionIndex]);
xbaddr startAddr = CxbxKrnl_Xbe->m_SectionHeader[sectionIndex].dwVirtualAddr;
xbaddr endAddr = startAddr + CxbxKrnl_Xbe->m_SectionHeader[sectionIndex].dwSizeofRaw;
for (xbaddr addr = startAddr; addr < endAddr; addr++)
@ -527,7 +527,7 @@ void EmuInitFS()
if (memcmp((void*)addr, &fsInstructions[i].data[0], sizeOfData) == 0)
{
DbgPrintf(CXBXR_MODULE::INIT, "Patching FS Instruction at 0x%.8X\n", addr);
DBG_PRINTF_EX(CXBXR_MODULE::INIT, "Patching FS Instruction at 0x%.8X\n", addr);
// Write Call opcode
*(uint08*)addr = OPCODE_CALL_E8;
@ -543,7 +543,7 @@ void EmuInitFS()
}
}
DbgPrintf(CXBXR_MODULE::INIT, "Done patching FS Register Accesses\n");
DBG_PRINTF_EX(CXBXR_MODULE::INIT, "Done patching FS Register Accesses\n");
}
// generate fs segment selector
@ -579,19 +579,19 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
#ifdef _DEBUG_TRACE
// dump raw TLS data
if (pNewTLS == nullptr) {
DbgPrintf(LOG_PREFIX, "TLS Non-Existant (OK)\n");
DBG_PRINTF("TLS Non-Existant (OK)\n");
} else {
DbgPrintf(LOG_PREFIX, "TLS Data Dump...\n");
DBG_PRINTF("TLS Data Dump...\n");
if (g_bPrintfOn) {
for (uint32 v = 0; v < dwCopySize; v++) {// Note : Don't dump dwZeroSize
uint08 *bByte = (uint08*)pNewTLS + v;
if (v % 0x10 == 0) {
DbgPrintf(LOG_PREFIX, "0x%.8X:", (xbaddr)bByte);
DBG_PRINTF("0x%.8X:", (xbaddr)bByte);
}
// Note : Use printf instead of DbgPrintf here, which prefixes with GetCurrentThreadId() :
// Note : Use printf instead of DBG_PRINTF here, which prefixes with GetCurrentThreadId() :
printf(" %.2X", *bByte);
}
@ -664,5 +664,5 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData)
// Make the KPCR struct available to KeGetPcr()
EmuKeSetPcr(NewPcr);
DbgPrintf(LOG_PREFIX, "Installed KPCR in TIB_ArbitraryDataSlot (with pTLS = 0x%.8X)\n", pTLS);
DBG_PRINTF("Installed KPCR in TIB_ArbitraryDataSlot (with pTLS = 0x%.8X)\n", pTLS);
}

View File

@ -462,13 +462,13 @@ NTSTATUS CxbxConvertFilePath(
replace_all( RelativePath, "\\\\", "\\" );
if (g_bPrintfOn) {
DbgPrintf(LOG_PREFIX, "%s Corrected path...\n", aFileAPIName.c_str());
DbgPrintf(LOG_PREFIX, " Org:\"%s\"\n", OriginalPath.c_str());
DBG_PRINTF("%s Corrected path...\n", aFileAPIName.c_str());
DBG_PRINTF(" Org:\"%s\"\n", OriginalPath.c_str());
if (_strnicmp(HostPath.c_str(), CxbxBasePath.c_str(), CxbxBasePath.length()) == 0) {
DbgPrintf(LOG_PREFIX, " New:\"$CxbxPath\\%s%s\"\n", (HostPath.substr(CxbxBasePath.length(), std::string::npos)).c_str(), RelativePath.c_str());
DBG_PRINTF(" New:\"$CxbxPath\\%s%s\"\n", (HostPath.substr(CxbxBasePath.length(), std::string::npos)).c_str(), RelativePath.c_str());
}
else
DbgPrintf(LOG_PREFIX, " New:\"$XbePath\\%s\"\n", RelativePath.c_str());
DBG_PRINTF(" New:\"$XbePath\\%s\"\n", RelativePath.c_str());
}
}
else
@ -667,7 +667,7 @@ NTSTATUS EmuNtSymbolicLinkObject::Init(std::string aSymbolicLinkName, std::strin
else
{
NtSymbolicLinkObjects[DriveLetter - 'A'] = this;
DbgPrintf(LOG_PREFIX, "Linked \"%s\" to \"%s\" (residing at \"%s\")\n", aSymbolicLinkName.c_str(), aFullPath.c_str(), HostSymbolicLinkPath.c_str());
DBG_PRINTF("Linked \"%s\" to \"%s\" (residing at \"%s\")\n", aSymbolicLinkName.c_str(), aFullPath.c_str(), HostSymbolicLinkPath.c_str());
}
}
}

View File

@ -239,7 +239,7 @@ XBSYSAPI EXPORTNUM(44) xboxkrnl::ULONG NTAPI xboxkrnl::HalGetInterruptVector
*Irql = (KIRQL)VECTOR2IRQL(dwVector);
#ifdef _DEBUG_TRACE
DbgPrintf(LOG_PREFIX, "HalGetInterruptVector(): Interrupt vector requested for %d (%s)\n",
DBG_PRINTF("HalGetInterruptVector(): Interrupt vector requested for %d (%s)\n",
BusInterruptLevel, IRQNames[BusInterruptLevel]);
#endif
}

View File

@ -307,7 +307,7 @@ XBSYSAPI EXPORTNUM(66) xboxkrnl::NTSTATUS NTAPI xboxkrnl::IoCreateFile
}
else
{
DbgPrintf(LOG_PREFIX, "IoCreateFile = 0x%.8X\n", *FileHandle);
DBG_PRINTF("IoCreateFile = 0x%.8X\n", *FileHandle);
}
RETURN(ret);

View File

@ -257,7 +257,7 @@ DWORD ExecuteDpcQueue()
pkdpc->Inserted = FALSE;
// Set DpcRoutineActive to support KeIsExecutingDpc:
KeGetCurrentPrcb()->DpcRoutineActive = TRUE; // Experimental
DbgPrintf(LOG_PREFIX, "Global DpcQueue, calling DPC at 0x%.8X\n", pkdpc->DeferredRoutine);
DBG_PRINTF("Global DpcQueue, calling DPC at 0x%.8X\n", pkdpc->DeferredRoutine);
__try {
// Call the Deferred Procedure :
pkdpc->DeferredRoutine(
@ -301,7 +301,7 @@ DWORD ExecuteDpcQueue()
if (pkdpc == nullptr)
break; // while
DbgPrintf(LOG_PREFIX, "Global TimerQueue, calling DPC at 0x%.8X\n", pkdpc->DeferredRoutine);
DBG_PRINTF("Global TimerQueue, calling DPC at 0x%.8X\n", pkdpc->DeferredRoutine);
__try {
pkdpc->DeferredRoutine(
@ -332,7 +332,7 @@ void InitDpcAndTimerThread()
InitializeListHead(&(g_DpcData.DpcQueue));
InitializeListHead(&(g_DpcData.TimerQueue));
DbgPrintf(CXBXR_MODULE::INIT, "Creating DPC event\n");
DBG_PRINTF_EX(CXBXR_MODULE::INIT, "Creating DPC event\n");
g_DpcData.DpcEvent = CreateEvent(/*lpEventAttributes=*/nullptr, /*bManualReset=*/FALSE, /*bInitialState=*/FALSE, /*lpName=*/nullptr);
}
@ -1213,9 +1213,9 @@ XBSYSAPI EXPORTNUM(126) xboxkrnl::ULONGLONG NTAPI xboxkrnl::KeQueryPerformanceCo
ULONGLONG ret;
//no matter rdtsc is patched or not, we should always return a scaled performance counter here.
DbgPrintf(LOG_PREFIX, "host tick count : %lu\n", CxbxRdTsc(/*xbox=*/false));
DBG_PRINTF("host tick count : %lu\n", CxbxRdTsc(/*xbox=*/false));
ret = CxbxRdTsc(/*xbox=*/true);
DbgPrintf(LOG_PREFIX, "emulated tick count : %lu\n", ret);
DBG_PRINTF("emulated tick count : %lu\n", ret);
RETURN(ret);
}
@ -1905,8 +1905,8 @@ xboxkrnl::PLARGE_INTEGER FASTCALL KiComputeWaitInterval(
return NewTime;
}
}
xboxkrnl::LIST_ENTRY KiWaitInListHead;
xboxkrnl::LIST_ENTRY KiWaitInListHead;
// ******************************************************************
// * 0x009E - KeWaitForMultipleObjects()
@ -2056,7 +2056,7 @@ XBSYSAPI EXPORTNUM(158) xboxkrnl::NTSTATUS NTAPI xboxkrnl::KeWaitForMultipleObje
/*
TODO: We can't implement this and the return values until we have our own thread schedular
For now, we'll have to implement waiting here instead of the schedular.
This code can all be enabled once we have CPU emulation and our own schedular in v1.0
This code can all be enabled once we have CPU emulation and our own schedular in v1.0
*/
// Insert the WaitBlock
@ -2096,9 +2096,9 @@ XBSYSAPI EXPORTNUM(158) xboxkrnl::NTSTATUS NTAPI xboxkrnl::KeWaitForMultipleObje
}
}
// Raise IRQL to DISPATCH_LEVEL and lock the database (only if it's not already at this level)
// Raise IRQL to DISPATCH_LEVEL and lock the database (only if it's not already at this level)
if (KeGetCurrentIrql() != DISPATCH_LEVEL) {
KiLockDispatcherDatabase(&Thread->WaitIrql);
KiLockDispatcherDatabase(&Thread->WaitIrql);
}
} while (TRUE);
@ -2191,7 +2191,7 @@ XBSYSAPI EXPORTNUM(159) xboxkrnl::NTSTATUS NTAPI xboxkrnl::KeWaitForSingleObject
goto NoWait;
}
// If we reached here, the wait could not be satisfied immediately, so we must setup a WaitBlock
// If we reached here, the wait could not be satisfied immediately, so we must setup a WaitBlock
Thread->WaitBlockList = WaitBlock;
WaitBlock->Object = Object;
WaitBlock->WaitKey = (CSHORT)(STATUS_SUCCESS);
@ -2225,12 +2225,12 @@ XBSYSAPI EXPORTNUM(159) xboxkrnl::NTSTATUS NTAPI xboxkrnl::KeWaitForSingleObject
else {
WaitBlock->NextWaitBlock = WaitBlock;
}
/*
/*
TODO: We can't implement this and the return values until we have our own thread schedular
For now, we'll have to implement waiting here instead of the schedular.
This code can all be enabled once we have CPU emulation and our own schedular in v1.0
*/
This code can all be enabled once we have CPU emulation and our own schedular in v1.0
*/
// Insert the WaitBlock
//InsertTailList(&ObjectMutant->Header.WaitListHead, &WaitBlock->WaitListEntry);
@ -2248,7 +2248,7 @@ XBSYSAPI EXPORTNUM(159) xboxkrnl::NTSTATUS NTAPI xboxkrnl::KeWaitForSingleObject
Thread->WaitTime = KeTickCount;
// TODO: Thread->State = Waiting;
//KiInsertWaitList(WaitMode, Thread);
/*
WaitStatus = (NTSTATUS)KiSwapThread();
@ -2259,7 +2259,7 @@ XBSYSAPI EXPORTNUM(159) xboxkrnl::NTSTATUS NTAPI xboxkrnl::KeWaitForSingleObject
// If the thread was not awakened for an APC, return the Wait Status
if (WaitStatus != STATUS_KERNEL_APC) {
return WaitStatus;
} */
} */
// TODO: Remove this after we have our own schedular and the above is implemented
Sleep(0);
@ -2272,7 +2272,7 @@ XBSYSAPI EXPORTNUM(159) xboxkrnl::NTSTATUS NTAPI xboxkrnl::KeWaitForSingleObject
// Raise IRQL to DISPATCH_LEVEL and lock the database
if (KeGetCurrentIrql() != DISPATCH_LEVEL) {
KiLockDispatcherDatabase(&Thread->WaitIrql);
KiLockDispatcherDatabase(&Thread->WaitIrql);
}
} while (TRUE);

View File

@ -416,15 +416,15 @@ XBSYSAPI EXPORTNUM(181) xboxkrnl::NTSTATUS NTAPI xboxkrnl::MmQueryStatistics
{
g_VMManager.MemoryStatistics(MemoryStatistics);
DbgPrintf(LOG_PREFIX, " MemoryStatistics->Length = 0x%.08X\n", MemoryStatistics->Length);
DbgPrintf(LOG_PREFIX, " MemoryStatistics->TotalPhysicalPages = 0x%.08X\n", MemoryStatistics->TotalPhysicalPages);
DbgPrintf(LOG_PREFIX, " MemoryStatistics->AvailablePages = 0x%.08X\n", MemoryStatistics->AvailablePages);
DbgPrintf(LOG_PREFIX, " MemoryStatistics->VirtualMemoryBytesCommitted = 0x%.08X\n", MemoryStatistics->VirtualMemoryBytesCommitted);
DbgPrintf(LOG_PREFIX, " MemoryStatistics->VirtualMemoryBytesReserved = 0x%.08X\n", MemoryStatistics->VirtualMemoryBytesReserved);
DbgPrintf(LOG_PREFIX, " MemoryStatistics->CachePagesCommitted = 0x%.08X\n", MemoryStatistics->CachePagesCommitted);
DbgPrintf(LOG_PREFIX, " MemoryStatistics->PoolPagesCommitted = 0x%.08X\n", MemoryStatistics->PoolPagesCommitted);
DbgPrintf(LOG_PREFIX, " MemoryStatistics->StackPagesCommitted = 0x%.08X\n", MemoryStatistics->StackPagesCommitted);
DbgPrintf(LOG_PREFIX, " MemoryStatistics->ImagePagesCommitted = 0x%.08X\n", MemoryStatistics->ImagePagesCommitted);
DBG_PRINTF(" MemoryStatistics->Length = 0x%.08X\n", MemoryStatistics->Length);
DBG_PRINTF(" MemoryStatistics->TotalPhysicalPages = 0x%.08X\n", MemoryStatistics->TotalPhysicalPages);
DBG_PRINTF(" MemoryStatistics->AvailablePages = 0x%.08X\n", MemoryStatistics->AvailablePages);
DBG_PRINTF(" MemoryStatistics->VirtualMemoryBytesCommitted = 0x%.08X\n", MemoryStatistics->VirtualMemoryBytesCommitted);
DBG_PRINTF(" MemoryStatistics->VirtualMemoryBytesReserved = 0x%.08X\n", MemoryStatistics->VirtualMemoryBytesReserved);
DBG_PRINTF(" MemoryStatistics->CachePagesCommitted = 0x%.08X\n", MemoryStatistics->CachePagesCommitted);
DBG_PRINTF(" MemoryStatistics->PoolPagesCommitted = 0x%.08X\n", MemoryStatistics->PoolPagesCommitted);
DBG_PRINTF(" MemoryStatistics->StackPagesCommitted = 0x%.08X\n", MemoryStatistics->StackPagesCommitted);
DBG_PRINTF(" MemoryStatistics->ImagePagesCommitted = 0x%.08X\n", MemoryStatistics->ImagePagesCommitted);
ret = STATUS_SUCCESS;
}

View File

@ -175,7 +175,7 @@ XBSYSAPI EXPORTNUM(187) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtClose
// Delete duplicate threads created by our implementation of NtQueueApcThread()
if( GetHandleInformation( g_DuplicateHandles[Handle], &flags ) != 0 )
{
DbgPrintf(LOG_PREFIX, "Closing duplicate handle...\n" );
DBG_PRINTF("Closing duplicate handle...\n" );
CloseHandle( g_DuplicateHandles[Handle] );
g_DuplicateHandles.erase(Handle);
@ -220,7 +220,7 @@ XBSYSAPI EXPORTNUM(188) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateDirectoryObje
if (FAILED(ret))
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtCreateDirectoryObject Failed!");
else
DbgPrintf(LOG_PREFIX, "NtCreateDirectoryObject DirectoryHandle = 0x%.8X\n", *DirectoryHandle);
DBG_PRINTF("NtCreateDirectoryObject DirectoryHandle = 0x%.8X\n", *DirectoryHandle);
RETURN(ret);
}
@ -297,10 +297,10 @@ XBSYSAPI EXPORTNUM(189) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateEvent
if(FAILED(ret))
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtCreateEvent Failed!");
else
DbgPrintf(LOG_PREFIX, "NtCreateEvent EventHandle = 0x%.8X\n", *EventHandle);
DBG_PRINTF("NtCreateEvent EventHandle = 0x%.8X\n", *EventHandle);
}
else
DbgPrintf(LOG_PREFIX, "NtCreateEvent EventHandle = 0x%.8X\n", *EventHandle);
DBG_PRINTF("NtCreateEvent EventHandle = 0x%.8X\n", *EventHandle);
RETURN(ret);
}
@ -425,10 +425,10 @@ XBSYSAPI EXPORTNUM(192) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateMutant
if(FAILED(ret))
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtCreateMutant Failed!");
else
DbgPrintf(LOG_PREFIX, "NtCreateMutant MutantHandle = 0x%.8X\n", *MutantHandle);
DBG_PRINTF("NtCreateMutant MutantHandle = 0x%.8X\n", *MutantHandle);
}
else
DbgPrintf(LOG_PREFIX, "NtCreateMutant MutantHandle = 0x%.8X\n", *MutantHandle);
DBG_PRINTF("NtCreateMutant MutantHandle = 0x%.8X\n", *MutantHandle);
RETURN(ret);
}
@ -500,10 +500,10 @@ XBSYSAPI EXPORTNUM(193) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateSemaphore
if(FAILED(ret))
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtCreateSemaphore failed!");
else
DbgPrintf(LOG_PREFIX, "NtCreateSemaphore SemaphoreHandle = 0x%.8X\n", *SemaphoreHandle);
DBG_PRINTF("NtCreateSemaphore SemaphoreHandle = 0x%.8X\n", *SemaphoreHandle);
}
else
DbgPrintf(LOG_PREFIX, "NtCreateSemaphore SemaphoreHandle = 0x%.8X\n", *SemaphoreHandle);
DBG_PRINTF("NtCreateSemaphore SemaphoreHandle = 0x%.8X\n", *SemaphoreHandle);
RETURN(ret);
}
@ -563,7 +563,7 @@ XBSYSAPI EXPORTNUM(194) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateTimer
if (FAILED(ret))
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtCreateTimer failed!");
else
DbgPrintf(LOG_PREFIX, "NtCreateTimer TimerHandle = 0x%.8X\n", *TimerHandle);
DBG_PRINTF("NtCreateTimer TimerHandle = 0x%.8X\n", *TimerHandle);
RETURN(ret);
}
@ -906,7 +906,7 @@ XBSYSAPI EXPORTNUM(203) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtOpenSymbolicLinkObj
if (ret != STATUS_SUCCESS)
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtOpenSymbolicLinkObject failed! (%s)", NtStatusToString(ret));
else
DbgPrintf(LOG_PREFIX, "NtOpenSymbolicLinkObject LinkHandle^ = 0x%.8X", *LinkHandle);
DBG_PRINTF("NtOpenSymbolicLinkObject LinkHandle^ = 0x%.8X", *LinkHandle);
RETURN(ret);
}
@ -1012,7 +1012,7 @@ XBSYSAPI EXPORTNUM(206) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueueApcThread
else
{
g_DuplicateHandles[ThreadHandle] = hApcThread; // Save this thread because we'll need to de-reference it later
DbgPrintf(LOG_PREFIX, "DuplicateHandle returned 0x%X (ThreadId 0x%.4X)\n", hApcThread, GetThreadId( hApcThread ) );
DBG_PRINTF("DuplicateHandle returned 0x%X (ThreadId 0x%.4X)\n", hApcThread, GetThreadId( hApcThread ) );
}
@ -1468,13 +1468,13 @@ XBSYSAPI EXPORTNUM(217) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryVirtualMemory
if (ret == STATUS_SUCCESS)
{
DbgPrintf(LOG_PREFIX, " Buffer->AllocationBase = 0x%.08X\n", Buffer->AllocationBase);
DbgPrintf(LOG_PREFIX, " Buffer->AllocationProtect = 0x%.08X\n", Buffer->AllocationProtect);
DbgPrintf(LOG_PREFIX, " Buffer->BaseAddress = 0x%.08X\n", Buffer->BaseAddress);
DbgPrintf(LOG_PREFIX, " Buffer->RegionSize = 0x%.08X\n", Buffer->RegionSize);
DbgPrintf(LOG_PREFIX, " Buffer->State = 0x%.08X\n", Buffer->State);
DbgPrintf(LOG_PREFIX, " Buffer->Protect = 0x%.08X\n", Buffer->Protect);
DbgPrintf(LOG_PREFIX, " Buffer->Type = 0x%.08X\n", Buffer->Type);
DBG_PRINTF(" Buffer->AllocationBase = 0x%.08X\n", Buffer->AllocationBase);
DBG_PRINTF(" Buffer->AllocationProtect = 0x%.08X\n", Buffer->AllocationProtect);
DBG_PRINTF(" Buffer->BaseAddress = 0x%.08X\n", Buffer->BaseAddress);
DBG_PRINTF(" Buffer->RegionSize = 0x%.08X\n", Buffer->RegionSize);
DBG_PRINTF(" Buffer->State = 0x%.08X\n", Buffer->State);
DBG_PRINTF(" Buffer->Protect = 0x%.08X\n", Buffer->Protect);
DBG_PRINTF(" Buffer->Type = 0x%.08X\n", Buffer->Type);
}
#if 0
@ -1498,7 +1498,7 @@ XBSYSAPI EXPORTNUM(217) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryVirtualMemory
ret = STATUS_SUCCESS;
DbgPrintf(LOG_PREFIX, "NtQueryVirtualMemory: Applied fix for Forza Motorsport!\n");
DBG_PRINTF("NtQueryVirtualMemory: Applied fix for Forza Motorsport!\n");
}
}
#endif
@ -2052,7 +2052,7 @@ XBSYSAPI EXPORTNUM(232) xboxkrnl::VOID NTAPI xboxkrnl::NtUserIoApcDispatcher
(CompletionRoutine)(dwErrorCode, dwTransferred, lpOverlapped);
DbgPrintf(LOG_PREFIX, "NtUserIoApcDispatcher Completed\n");
DBG_PRINTF("NtUserIoApcDispatcher Completed\n");
}
// ******************************************************************

View File

@ -160,7 +160,7 @@ static unsigned int WINAPI PCSTProxy
if (pfnNotificationRoutine == NULL)
continue;
DbgPrintf(LOG_PREFIX, "Calling pfnNotificationRoutine[%d] (0x%.8X)\n", g_iThreadNotificationCount, pfnNotificationRoutine);
DBG_PRINTF("Calling pfnNotificationRoutine[%d] (0x%.8X)\n", g_iThreadNotificationCount, pfnNotificationRoutine);
pfnNotificationRoutine(TRUE);
}
@ -327,7 +327,7 @@ XBSYSAPI EXPORTNUM(255) xboxkrnl::NTSTATUS NTAPI xboxkrnl::PsCreateSystemThreadE
// Give the thread chance to start
Sleep(100);
DbgPrintf(LOG_PREFIX, "Waiting for Xbox proxy thread to start...\n");
DBG_PRINTF("Waiting for Xbox proxy thread to start...\n");
while (bWait) {
dwThreadWait = WaitForSingleObject(hStartedEvent, 300);
@ -338,7 +338,7 @@ XBSYSAPI EXPORTNUM(255) xboxkrnl::NTSTATUS NTAPI xboxkrnl::PsCreateSystemThreadE
break;
}
case WAIT_OBJECT_0: { // The state of the specified object is signaled.
DbgPrintf(LOG_PREFIX, "Xbox proxy thread is started.\n");
DBG_PRINTF("Xbox proxy thread is started.\n");
bWait = false;
break;
}
@ -358,7 +358,7 @@ XBSYSAPI EXPORTNUM(255) xboxkrnl::NTSTATUS NTAPI xboxkrnl::PsCreateSystemThreadE
hStartedEvent = NULL;
// Log ThreadID identical to how GetCurrentThreadID() is rendered :
DbgPrintf(LOG_PREFIX, "Created Xbox proxy thread. Handle : 0x%X, ThreadId : [0x%.4X]\n", *ThreadHandle, dwThreadId);
DBG_PRINTF("Created Xbox proxy thread. Handle : 0x%X, ThreadId : [0x%.4X]\n", *ThreadHandle, dwThreadId);
CxbxKrnlRegisterThread(*ThreadHandle);
@ -451,7 +451,7 @@ XBSYSAPI EXPORTNUM(258) xboxkrnl::VOID NTAPI xboxkrnl::PsTerminateSystemThread
if (pfnNotificationRoutine == NULL)
continue;
DbgPrintf(LOG_PREFIX, "Calling pfnNotificationRoutine[%d] (0x%.8X)\n", g_iThreadNotificationCount, pfnNotificationRoutine);
DBG_PRINTF("Calling pfnNotificationRoutine[%d] (0x%.8X)\n", g_iThreadNotificationCount, pfnNotificationRoutine);
pfnNotificationRoutine(FALSE);
}

View File

@ -654,7 +654,7 @@ XBSYSAPI EXPORTNUM(277) xboxkrnl::VOID NTAPI xboxkrnl::RtlEnterCriticalSection
CriticalSection->RecursionCount = 1;
}
else {
if(CriticalSection->OwningThread != thread) {
if(CriticalSection->OwningThread != thread) {
if (CriticalSection->OwningThread != nullptr) {
NTSTATUS result;
result = KeWaitForSingleObject(
@ -667,7 +667,7 @@ XBSYSAPI EXPORTNUM(277) xboxkrnl::VOID NTAPI xboxkrnl::RtlEnterCriticalSection
if (!NT_SUCCESS(result))
{
CxbxKrnlCleanup(LOG_PREFIX, "Waiting for event of a critical section returned %lx.", result);
};
};
}
CriticalSection->OwningThread = thread;
CriticalSection->RecursionCount = 1;
@ -1387,7 +1387,7 @@ XBSYSAPI EXPORTNUM(301) xboxkrnl::ULONG NTAPI xboxkrnl::RtlNtStatusToDosError
return LOWORD(Status);
no_mapping:
DbgPrintf(LOG_PREFIX, "no mapping for %08x\n", Status);
DBG_PRINTF("no mapping for %08x\n", Status);
ret = ERROR_MR_MID_NOT_FOUND;
*/
RETURN(ret);

View File

@ -176,7 +176,7 @@ uint32_t EmuFlash_Read32(xbaddr addr) // TODO : Move to EmuFlash.cpp
return -1;
}
DbgPrintf(LOG_PREFIX, "Read32 FLASH_ROM (0x%.8X) = 0x%.8X [HANDLED]\n", addr, r);
DBG_PRINTF("Read32 FLASH_ROM (0x%.8X) = 0x%.8X [HANDLED]\n", addr, r);
return r;
}
@ -208,7 +208,7 @@ uint32_t EmuX86_Read(xbaddr addr, int size)
//pass the memory-access through to normal memory :
value = EmuX86_Mem_Read(addr, size);
DbgPrintf(LOG_PREFIX, "Read(0x%08X, %d) = 0x%08X\n", addr, size, value);
DBG_PRINTF("Read(0x%08X, %d) = 0x%08X\n", addr, size, value);
}
return value;
@ -233,7 +233,7 @@ void EmuX86_Write(xbaddr addr, uint32_t value, int size)
}
// Pass the memory-access through to normal memory :
DbgPrintf(LOG_PREFIX, "Write(0x%.8X, 0x%.8X, %d)\n", addr, value, size);
DBG_PRINTF("Write(0x%.8X, 0x%.8X, %d)\n", addr, value, size);
EmuX86_Mem_Write(addr, value, size);
}
@ -2595,8 +2595,9 @@ bool EmuX86_DecodeException(LPEXCEPTION_POINTERS e)
return false;
}
if (1) //
LOG_CHECK_ENABLED(LOG_LEVEL::DEBUG) {
EmuX86_DistormLogInstruction((uint8_t*)e->ContextRecord->Eip, info);
}
switch (info.opcode) { // Keep these cases alphabetically ordered and condensed
case I_ADD:
@ -2926,7 +2927,7 @@ opcode_error:
void EmuX86_Init()
{
DbgPrintf(LOG_PREFIX, "Initializing distorm version %d\n", distorm_version());
DBG_PRINTF("Initializing distorm version %d\n", distorm_version());
AddVectoredExceptionHandler(/*FirstHandler=*/ULONG(true), lleException);

View File

@ -37,7 +37,7 @@
#define LOG_PREFIX CXBXR_MODULE::PMEM
#include "PhysicalMemory.h"
#include "PhysicalMemory.h"
#include "Logging.h"
#include <assert.h>
@ -553,7 +553,7 @@ DWORD PhysicalMemory::PatchXboxPermissions(DWORD Perms)
{
// One of XBOX_PAGE_READONLY or XBOX_PAGE_READWRITE must be specified
DbgPrintf(LOG_PREFIX, "%s: Memory permissions bug detected\n", __func__);
DBG_PRINTF("%s: Memory permissions bug detected\n", __func__);
return XBOX_PAGE_EXECUTE_READWRITE;
}
@ -574,7 +574,7 @@ DWORD PhysicalMemory::PatchXboxPermissions(DWORD Perms)
// If we reach here it means that both XBOX_PAGE_READONLY and XBOX_PAGE_READWRITE were specified, and so the
// input is probably invalid
DbgPrintf(LOG_PREFIX, "%s: Memory permissions bug detected\n", __func__);
DBG_PRINTF("%s: Memory permissions bug detected\n", __func__);
return XBOX_PAGE_EXECUTE_READWRITE;
}
}
@ -640,7 +640,7 @@ DWORD PhysicalMemory::ConvertXboxToWinProtection(DWORD Perms)
// If we reach here it means that more than one permission modifier was specified, and so the input is
// probably invalid
DbgPrintf(LOG_PREFIX, "%s: Memory permissions bug detected\n", __func__);
DBG_PRINTF("%s: Memory permissions bug detected\n", __func__);
return PAGE_EXECUTE_READWRITE;
}
}

View File

@ -77,11 +77,11 @@ void VMManager::Initialize(HANDLE memory_view, HANDLE pagetables_view, int BootF
ConstructMemoryRegion(CONTIGUOUS_MEMORY_BASE, CONTIGUOUS_MEMORY_XBOX_SIZE, ContiguousRegion);
ConstructMemoryRegion(SYSTEM_MEMORY_BASE, SYSTEM_MEMORY_SIZE, SystemRegion);
ConstructMemoryRegion(DEVKIT_MEMORY_BASE, DEVKIT_MEMORY_SIZE, DevkitRegion);
unsigned char PreviousLayout;
if ((BootFlags & BOOT_QUICK_REBOOT) != 0)
{
// Restore the memory layout we were emulating in the previous session
// Restore the memory layout we were emulating in the previous session
PreviousLayout = *(unsigned char*)(CONTIGUOUS_MEMORY_BASE + PAGE_SIZE - 9);
m_MmLayoutChihiro = (PreviousLayout == MmChihiro);
@ -93,10 +93,10 @@ void VMManager::Initialize(HANDLE memory_view, HANDLE pagetables_view, int BootF
// Save the type of xbe we are emulating in this emulation session. This information will be needed if the current xbe performs
// a quick reboot
m_MmLayoutChihiro = (g_XbeType == xtChihiro);
m_MmLayoutDebug = (g_XbeType == xtDebug);
m_MmLayoutChihiro = (g_XbeType == xtChihiro);
m_MmLayoutDebug = (g_XbeType == xtDebug);
m_MmLayoutRetail = (g_XbeType == xtRetail);
PreviousLayout = m_MmLayoutChihiro ? MmChihiro : (m_MmLayoutDebug ? MmDebug : MmRetail);
}
@ -138,7 +138,7 @@ void VMManager::Initialize(HANDLE memory_view, HANDLE pagetables_view, int BootF
// The memory manager needs updating to only persist areas of memory marked with MmPersistContiguousMemory and discard the rest.
// But right now it persists the whole block". So we also clear the entire mapped memory.bin since we are not quick rebooting
xboxkrnl::RtlFillMemoryUlong((void*)CONTIGUOUS_MEMORY_BASE, g_SystemMaxMemory, 0);
xboxkrnl::RtlFillMemoryUlong((void*)PAGE_TABLES_BASE, PAGE_TABLES_SIZE, 0);
xboxkrnl::RtlFillMemoryUlong((void*)PAGE_TABLES_BASE, PAGE_TABLES_SIZE, 0);
*(unsigned char*)(CONTIGUOUS_MEMORY_BASE + PAGE_SIZE - 9) = PreviousLayout;
InitializePfnDatabase();
}
@ -155,7 +155,7 @@ void VMManager::Initialize(HANDLE memory_view, HANDLE pagetables_view, int BootF
InitializePageDirectory();
// Reserve the xbe image memory. Doing this now allows us to avoid calling XbAllocateVirtualMemory later
ConstructVMA(XBE_IMAGE_BASE, ROUND_UP_4K(CxbxKrnl_Xbe->m_Header.dwSizeofImage), UserRegion, ReservedVma, false, XBOX_PAGE_READWRITE);
ConstructVMA(XBE_IMAGE_BASE, ROUND_UP_4K(CxbxKrnl_Xbe->m_Header.dwSizeofImage), UserRegion, ReservedVma, false, XBOX_PAGE_READWRITE);
m_VirtualMemoryBytesReserved += ROUND_UP_4K(CxbxKrnl_Xbe->m_Header.dwSizeofImage);
if (m_MmLayoutChihiro) {
@ -574,7 +574,7 @@ VAddr VMManager::ClaimGpuMemory(size_t Size, size_t* BytesToSkip)
}
m_NV2AInstanceMemoryBytes = Size;
DbgPrintf(LOG_PREFIX, "MmClaimGpuInstanceMemory : Allocated bytes remaining = 0x%.8X\n", m_NV2AInstanceMemoryBytes);
DBG_PRINTF("MmClaimGpuInstanceMemory : Allocated bytes remaining = 0x%.8X\n", m_NV2AInstanceMemoryBytes);
Unlock();
}
@ -621,12 +621,12 @@ void VMManager::PersistMemory(VAddr addr, size_t Size, bool bPersist)
if (bPersist)
{
*(VAddr*)(CONTIGUOUS_MEMORY_BASE + PAGE_SIZE - 4) = addr;
DbgPrintf(LOG_PREFIX, "Persisting LaunchDataPage\n");
DBG_PRINTF("Persisting LaunchDataPage\n");
}
else
{
*(VAddr*)(CONTIGUOUS_MEMORY_BASE + PAGE_SIZE - 4) = NULL;
DbgPrintf(LOG_PREFIX, "Forgetting LaunchDataPage\n");
DBG_PRINTF("Forgetting LaunchDataPage\n");
}
}
else
@ -634,12 +634,12 @@ void VMManager::PersistMemory(VAddr addr, size_t Size, bool bPersist)
if (bPersist)
{
*(VAddr*)(CONTIGUOUS_MEMORY_BASE + PAGE_SIZE - 8) = addr;
DbgPrintf(LOG_PREFIX, "Persisting FrameBuffer\n");
DBG_PRINTF("Persisting FrameBuffer\n");
}
else
{
*(VAddr*)(CONTIGUOUS_MEMORY_BASE + PAGE_SIZE - 8) = NULL;
DbgPrintf(LOG_PREFIX, "Forgetting FrameBuffer\n");
DBG_PRINTF("Forgetting FrameBuffer\n");
}
}
}
@ -707,7 +707,7 @@ void VMManager::RestorePersistentMemory()
RestorePersistentAllocation(LauchDataAddress, GetPteAddress(LauchDataAddress)->Hardware.PFN,
GetPteAddress(LauchDataAddress)->Hardware.PFN, ContiguousType);
DbgPrintf(LOG_PREFIX, "Restored LaunchDataPage\n");
DBG_PRINTF("Restored LaunchDataPage\n");
}
if (FrameBufferAddress != 0 && IS_PHYSICAL_ADDRESS(FrameBufferAddress)) {
@ -717,7 +717,7 @@ void VMManager::RestorePersistentMemory()
RestorePersistentAllocation(FrameBufferAddress, GetPteAddress(FrameBufferAddress)->Hardware.PFN,
GetPteAddress(FrameBufferAddress)->Hardware.PFN + (QuerySize(FrameBufferAddress, false) >> PAGE_SHIFT) - 1, ContiguousType);
DbgPrintf(LOG_PREFIX, "Restored FrameBuffer\n");
DBG_PRINTF("Restored FrameBuffer\n");
}
}
}
@ -1086,9 +1086,9 @@ VAddr VMManager::MapDeviceMemory(PAddr Paddr, size_t Size, DWORD Perms)
if (!addr) { goto Fail; }
// check if we have to construct the PT's for this allocation
if (!AllocatePT(PteNumber << PAGE_SHIFT, addr)) {
VirtualFree((void*)addr, 0, MEM_RELEASE);
goto Fail;
if (!AllocatePT(PteNumber << PAGE_SHIFT, addr)) {
VirtualFree((void*)addr, 0, MEM_RELEASE);
goto Fail;
}
// Finally, write the pte's
@ -1119,7 +1119,7 @@ void VMManager::Deallocate(VAddr addr)
PFN pfn;
PFN EndingPfn;
PFN_COUNT PteNumber;
VMAIter it;
VMAIter it;
bool bOverflow;
assert(CHECK_ALIGNMENT(addr, PAGE_SIZE)); // all starting addresses in the user region are page aligned
@ -1178,7 +1178,7 @@ void VMManager::DeallocateContiguous(VAddr addr)
PMMPTE EndingPte;
PFN pfn;
PFN EndingPfn;
VMAIter it;
VMAIter it;
bool bOverflow;
assert(CHECK_ALIGNMENT(addr, PAGE_SIZE)); // all starting addresses in the contiguous region are page aligned
@ -1223,7 +1223,7 @@ PFN_COUNT VMManager::DeallocateSystemMemory(PageType BusyType, VAddr addr, size_
PFN_COUNT PteNumber;
VMAIter it;
MemoryRegionType MemoryType = SystemRegion;
bool bGuardPageAdded = false;
bool bGuardPageAdded = false;
bool bOverflow;
assert(CHECK_ALIGNMENT(addr, PAGE_SIZE)); // all starting addresses in the system region are page aligned
@ -1303,14 +1303,14 @@ void VMManager::UnmapDeviceMemory(VAddr addr, size_t Size)
PMMPTE StartingPte;
PMMPTE EndingPte;
PFN_COUNT PteNumber;
VMAIter it;
VMAIter it;
bool bOverflow;
// The starting address of a device can be unaligned since MapDeviceMemory returns an offset from the aligned
// mapped address, so we won't assert the address here
Lock();
Size = PAGES_SPANNED(addr, Size) << PAGE_SHIFT;
it = CheckConflictingVMA(addr, Size, SystemRegion, &bOverflow);
@ -1443,7 +1443,7 @@ size_t VMManager::QuerySize(VAddr addr, bool bCxbxCaller)
else if(IS_USER_ADDRESS(addr)) { Type = UserRegion; }
else
{
DbgPrintf(LOG_PREFIX, "QuerySize: Unknown memory region queried.\n");
DBG_PRINTF("QuerySize: Unknown memory region queried.\n");
Unlock();
RETURN(Size);
}
@ -1600,7 +1600,7 @@ xboxkrnl::NTSTATUS VMManager::XbAllocateVirtualMemory(VAddr* addr, ULONG ZeroBit
if (!ConvertXboxToPteProtection(Protect, &TempPte)) { RETURN(STATUS_INVALID_PAGE_PROTECTION); }
DbgPrintf(LOG_PREFIX, "%s requested range : 0x%.8X - 0x%.8X\n", __func__, CapturedBase, CapturedBase + CapturedSize);
DBG_PRINTF("%s requested range : 0x%.8X - 0x%.8X\n", __func__, CapturedBase, CapturedBase + CapturedSize);
Lock();
@ -1648,18 +1648,18 @@ xboxkrnl::NTSTATUS VMManager::XbAllocateVirtualMemory(VAddr* addr, ULONG ZeroBit
status = STATUS_CONFLICTING_ADDRESSES;
goto Exit;
}
// Hack: check if the title is attempting to reserve in the region between the reserved xbe image memory up to XBE_MAX_VA.
}
// Hack: check if the title is attempting to reserve in the region between the reserved xbe image memory up to XBE_MAX_VA.
// Once the memory placeholder is gone, this can be removed.
// Note: this will not work if the title attempts to reserve inside the placeholder with a size that makes the
// allocation exceed the end of the placeholder at XBE_MAX_VA (e.g.: Fable does this!) and it doesn't accept
// any other address but the requested one (e.g.: Project Zero 1 does this!). No title is known to do this, but it's
// Note: this will not work if the title attempts to reserve inside the placeholder with a size that makes the
// allocation exceed the end of the placeholder at XBE_MAX_VA (e.g.: Fable does this!) and it doesn't accept
// any other address but the requested one (e.g.: Project Zero 1 does this!). No title is known to do this, but it's
// teoretically possible...
if (AlignedCapturedBase < XBE_MAX_VA && AlignedCapturedBase >= ROUND_UP_4K(CxbxKrnl_Xbe->m_Header.dwSizeofImage) + XBE_IMAGE_BASE
if (AlignedCapturedBase < XBE_MAX_VA && AlignedCapturedBase >= ROUND_UP_4K(CxbxKrnl_Xbe->m_Header.dwSizeofImage) + XBE_IMAGE_BASE
&& AlignedCapturedBase + AlignedCapturedSize - 1 < XBE_MAX_VA)
{
{
// Don't do anything, ConstructVMA will be called below to track the allocation inside the placeholder
}
else {
@ -1670,7 +1670,7 @@ xboxkrnl::NTSTATUS VMManager::XbAllocateVirtualMemory(VAddr* addr, ULONG ZeroBit
status = STATUS_CONFLICTING_ADDRESSES;
goto Exit;
}
}
}
}
@ -1681,7 +1681,7 @@ xboxkrnl::NTSTATUS VMManager::XbAllocateVirtualMemory(VAddr* addr, ULONG ZeroBit
{
// XBOX_MEM_COMMIT was not specified, so we are done with the allocation
DbgPrintf(LOG_PREFIX, "%s resulting range : 0x%.8X - 0x%.8X\n", __func__, AlignedCapturedBase, AlignedCapturedBase + AlignedCapturedSize);
DBG_PRINTF("%s resulting range : 0x%.8X - 0x%.8X\n", __func__, AlignedCapturedBase, AlignedCapturedBase + AlignedCapturedSize);
*addr = AlignedCapturedBase;
*Size = AlignedCapturedSize;
@ -1768,7 +1768,7 @@ xboxkrnl::NTSTATUS VMManager::XbAllocateVirtualMemory(VAddr* addr, ULONG ZeroBit
PointerPte++;
}
// Actually commit the requested range but don't if it's inside the placeholder or we are committing an xbe section so that
// Actually commit the requested range but don't if it's inside the placeholder or we are committing an xbe section so that
// XeLoadSection works as expected
if (AlignedCapturedBase >= XBE_MAX_VA)
@ -1776,13 +1776,13 @@ xboxkrnl::NTSTATUS VMManager::XbAllocateVirtualMemory(VAddr* addr, ULONG ZeroBit
if (!VirtualAlloc((void*)AlignedCapturedBase, AlignedCapturedSize, MEM_COMMIT,
(ConvertXboxToWinProtection(PatchXboxPermissions(Protect))) & ~(PAGE_WRITECOMBINE | PAGE_NOCACHE)))
{
DbgPrintf(LOG_PREFIX, "%s: VirtualAlloc failed to commit the memory! The error was %d\n", __func__, GetLastError());
DBG_PRINTF("%s: VirtualAlloc failed to commit the memory! The error was %d\n", __func__, GetLastError());
}
}
// Because VirtualAlloc always zeros the memory for us, XBOX_MEM_NOZERO is still unsupported
if (AllocationType & XBOX_MEM_NOZERO) { DbgPrintf(LOG_PREFIX, "XBOX_MEM_NOZERO flag is not supported!\n"); }
if (AllocationType & XBOX_MEM_NOZERO) { DBG_PRINTF("XBOX_MEM_NOZERO flag is not supported!\n"); }
// If some pte's were detected to have different permissions in the above check, we need to update those as well
@ -1794,7 +1794,7 @@ xboxkrnl::NTSTATUS VMManager::XbAllocateVirtualMemory(VAddr* addr, ULONG ZeroBit
XbVirtualProtect(&TempAddr, &TempSize, &TempProtect);
}
DbgPrintf(LOG_PREFIX, "%s resulting range : 0x%.8X - 0x%.8X\n", __func__, AlignedCapturedBase, AlignedCapturedBase + AlignedCapturedSize);
DBG_PRINTF("%s resulting range : 0x%.8X - 0x%.8X\n", __func__, AlignedCapturedBase, AlignedCapturedBase + AlignedCapturedSize);
*addr = AlignedCapturedBase;
*Size = AlignedCapturedSize;
@ -1950,13 +1950,13 @@ xboxkrnl::NTSTATUS VMManager::XbFreeVirtualMemory(VAddr* addr, size_t* Size, DWO
if (FreeType & ~XBOX_MEM_RELEASE)
{
// With XBOX_MEM_DECOMMIT DestructVMA is not called and so we have to call VirtualFree ourselves
if (AlignedCapturedBase >= XBE_MAX_VA)
if (AlignedCapturedBase >= XBE_MAX_VA)
{
if (!VirtualFree((void*)AlignedCapturedBase, AlignedCapturedSize, MEM_DECOMMIT))
{
DbgPrintf(LOG_PREFIX, "%s: VirtualFree failed to decommit the memory! The error was %d\n", __func__, GetLastError());
}
DBG_PRINTF("%s: VirtualFree failed to decommit the memory! The error was %d\n", __func__, GetLastError());
}
}
}
@ -2110,9 +2110,9 @@ xboxkrnl::NTSTATUS VMManager::XbVirtualMemoryStatistics(VAddr addr, xboxkrnl::PM
}
// If it's not in the placeholder, report actual host allocations. The game will see allocations it didn't make, but at least it has a chance to
// not try to allocate memory our emulator already occupied.
// Note1: VirtualQuery will always report the placeholder as committed, even when the VMManager will report it as free, so we need to query it
// ourselves to correctly report committed/free areas in the placeholder.
// not try to allocate memory our emulator already occupied.
// Note1: VirtualQuery will always report the placeholder as committed, even when the VMManager will report it as free, so we need to query it
// ourselves to correctly report committed/free areas in the placeholder.
// Note2: when LLE CPU is implemented, this can be removed.
if (addr >= XBE_MAX_VA)
{
@ -2138,12 +2138,12 @@ xboxkrnl::NTSTATUS VMManager::XbVirtualMemoryStatistics(VAddr addr, xboxkrnl::PM
// Locate the vma containing the supplied address
it = GetVMAIterator(addr, UserRegion);
if (addr < LOWEST_USER_ADDRESS || (it != m_MemoryRegionArray[UserRegion].RegionMap.end() && it->second.type == FreeVma)) {
if (addr < LOWEST_USER_ADDRESS || (it != m_MemoryRegionArray[UserRegion].RegionMap.end() && it->second.type == FreeVma)) {
// The address belongs to a free VMA, so we have little to do.
if (addr < LOWEST_USER_ADDRESS) {
RegionSize = LOWEST_USER_ADDRESS - ROUND_DOWN_4K(addr);
}
// The address belongs to a free VMA, so we have little to do.
if (addr < LOWEST_USER_ADDRESS) {
RegionSize = LOWEST_USER_ADDRESS - ROUND_DOWN_4K(addr);
}
else { RegionSize = it->first + it->second.size - ROUND_DOWN_4K(addr); }
memory_statistics->AllocationBase = NULL;
@ -2413,37 +2413,37 @@ PAddr VMManager::TranslateVAddrToPAddr(const VAddr addr)
//if (IS_USER_ADDRESS(addr)) { Type = UserRegion; }
//else if (IS_PHYSICAL_ADDRESS(addr)) { Type = ContiguousRegion; }
//else if (IS_SYSTEM_ADDRESS(addr)) { Type = SystemRegion; }
//else if (IS_DEVKIT_ADDRESS(addr)) { Type = DevkitRegion; }
//else if (IS_DEVKIT_ADDRESS(addr)) { Type = DevkitRegion; }
//else { Type = COUNTRegion; }
if (true/*(addr >= PAGE_TABLES_BASE && addr <= PAGE_TABLES_END) || (Type != COUNTRegion && Type != ContiguousRegion)*/) {
if (IsValidVirtualAddress(addr)) {
if (IsValidVirtualAddress(addr)) {
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Applying identity mapping hack to allocation at address 0x%X", addr);
Unlock();
RETURN(addr);
RETURN(addr);
/*
if (Type == UserRegion) {
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Applying identity mapping hack to allocation at address 0x%X", addr);
Unlock();
RETURN(addr); // committed pages in the user region always use VirtualAlloc
}
}
else if (Type != COUNTRegion) {
VMAIter it = GetVMAIterator(addr, Type);
if (it != m_MemoryRegionArray[Type].RegionMap.end() && it->second.type != FreeVma && it->second.bFragmented) {
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Applying identity mapping hack to allocation at address 0x%X", addr);
Unlock();
RETURN(addr); // committed pages in the system-devkit regions can use VirtualAlloc because of fragmentation
}
}
else {
// This is the special case of the page tables region at 0xC0000000. This area doesn't have a memory region assigned to,
// and never uses VirtualAlloc, but it's still affected by the above problem since its physical pages don't come from
// our memory.bin at 0x80000000, so it needs the hack as well.
}
}
else {
// This is the special case of the page tables region at 0xC0000000. This area doesn't have a memory region assigned to,
// and never uses VirtualAlloc, but it's still affected by the above problem since its physical pages don't come from
// our memory.bin at 0x80000000, so it needs the hack as well.
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Applying identity mapping hack to allocation at address 0x%X", addr);
Unlock();
RETURN(addr);
}
}
*/
}
else {
@ -2615,7 +2615,7 @@ void VMManager::UpdateMemoryPermissions(VAddr addr, size_t Size, DWORD Perms)
DWORD dummy;
if (!VirtualProtect((void*)addr, Size, WindowsPerms & ~(PAGE_WRITECOMBINE | PAGE_NOCACHE), &dummy))
{
DbgPrintf(LOG_PREFIX, "VirtualProtect failed. The error code was %d\n", GetLastError());
DBG_PRINTF("VirtualProtect failed. The error code was %d\n", GetLastError());
}
}
@ -2624,21 +2624,21 @@ VMAIter VMManager::CheckConflictingVMA(VAddr addr, size_t Size, MemoryRegionType
*bOverflow = false;
VMAIter it = GetVMAIterator(addr, Type);
if (it == m_MemoryRegionArray[Type].RegionMap.end()) {
// Pretend we are overflowing since an overflow is always an error. Otherwise, end() will be interpreted
// as a found free VMA.
*bOverflow = true;
return it;
}
if (it == m_MemoryRegionArray[Type].RegionMap.end()) {
// Pretend we are overflowing since an overflow is always an error. Otherwise, end() will be interpreted
// as a found free VMA.
*bOverflow = true;
return it;
}
if (Size != 0 && (it->first + it->second.size - 1 < addr + Size - 1)) {
*bOverflow = true;
}
if (it->second.type != FreeVma) {
}
if (it->second.type != FreeVma) {
return it; // conflict
}
}
return m_MemoryRegionArray[Type].RegionMap.end(); // no conflict
}
@ -2669,7 +2669,7 @@ void VMManager::DestructVMA(VAddr addr, MemoryRegionType Type, size_t Size)
if (!ret)
{
DbgPrintf(LOG_PREFIX, "Deallocation routine failed with error %d\n", GetLastError());
DBG_PRINTF("Deallocation routine failed with error %d\n", GetLastError());
}
}
@ -2695,7 +2695,7 @@ void VMManager::DestructVMA(VAddr addr, MemoryRegionType Type, size_t Size)
}
else
{
DbgPrintf(LOG_PREFIX, "std::prev(CarvedVmaIt) was not free\n");
DBG_PRINTF("std::prev(CarvedVmaIt) was not free\n");
it = CarvedVmaIt;

View File

@ -213,7 +213,7 @@ g_EmuCDPD = {0};
#define DEBUG_D3DRESULT(hRet, message) \
do { \
LOG_CHECK_ENABLED(CXBXR_MODULE::D3D8, LOG_LEVEL::DEBUG) { \
LOG_CHECK_ENABLED(LOG_LEVEL::DEBUG) { \
if (FAILED(hRet)) \
if(g_bPrintfOn) \
printf("%s%s : %s D3D error (0x%.08X: %s)\n", _logThreadPrefix.c_str(), _logFuncPrefix.c_str(), message, hRet, D3DErrorString(hRet)); \
@ -1462,7 +1462,7 @@ static DWORD WINAPI EmuRenderWindow(LPVOID lpVoid)
}
}
DbgPrintf(LOG_PREFIX, "Message-Pump thread is running.\n");
DBG_PRINTF("Message-Pump thread is running.\n");
SetFocus(g_hEmuWindow);
@ -1741,7 +1741,7 @@ static DWORD WINAPI EmuUpdateTickCount(LPVOID)
// since callbacks come from here
InitXboxThread(g_CPUOthers); // avoid Xbox1 core for lowest possible latency
DbgPrintf(LOG_PREFIX, "Timing thread is running.\n");
DBG_PRINTF("Timing thread is running.\n");
// current vertical blank count
int curvb = 0;
@ -1902,18 +1902,18 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID)
CxbxSetThreadName("Cxbx CreateDevice Proxy");
DbgPrintf(LOG_PREFIX, "CreateDevice proxy thread is running.\n");
DBG_PRINTF("CreateDevice proxy thread is running.\n");
while(true)
{
// if we have been signalled, create the device with cached parameters
if(g_EmuCDPD.bReady)
{
DbgPrintf(LOG_PREFIX, "CreateDevice proxy thread received request.\n");
DBG_PRINTF("CreateDevice proxy thread received request.\n");
// only one device should be created at once
if (g_pD3DDevice != nullptr) {
DbgPrintf(LOG_PREFIX, "CreateDevice proxy thread releasing old Device.\n");
DBG_PRINTF("CreateDevice proxy thread releasing old Device.\n");
g_pD3DDevice->EndScene();
@ -2020,13 +2020,13 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID)
{
const char* resolution = g_XBVideo.szVideoResolution;
if (2 != sscanf(resolution, "%u x %u", &g_EmuCDPD.HostPresentationParameters.BackBufferWidth, &g_EmuCDPD.HostPresentationParameters.BackBufferHeight)) {
DbgPrintf(LOG_PREFIX, "EmuCreateDeviceProxy: Couldn't parse resolution : %s.\n", resolution);
DBG_PRINTF("EmuCreateDeviceProxy: Couldn't parse resolution : %s.\n", resolution);
}
else {
if (g_EmuCDPD.HostPresentationParameters.BackBufferWidth == 640)
DbgPrintf(LOG_PREFIX, "EmuCreateDeviceProxy: Default width wasn't updated.\n");
DBG_PRINTF("EmuCreateDeviceProxy: Default width wasn't updated.\n");
if (g_EmuCDPD.HostPresentationParameters.BackBufferWidth == 480)
DbgPrintf(LOG_PREFIX, "EmuCreateDeviceProxy: Default height wasn't updated.\n");
DBG_PRINTF("EmuCreateDeviceProxy: Default height wasn't updated.\n");
}
XTL::D3DDISPLAYMODE D3DDisplayMode;
@ -2046,13 +2046,13 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID)
&g_EmuCDPD.HostPresentationParameters.BackBufferHeight,
szBackBufferFormat,
&g_EmuCDPD.HostPresentationParameters.FullScreen_RefreshRateInHz)) {
DbgPrintf(LOG_PREFIX, "EmuCreateDeviceProxy: Couldn't parse resolution : %s.\n", resolution);
DBG_PRINTF("EmuCreateDeviceProxy: Couldn't parse resolution : %s.\n", resolution);
}
else {
if (g_EmuCDPD.HostPresentationParameters.BackBufferWidth == 640)
DbgPrintf(LOG_PREFIX, "EmuCreateDeviceProxy: Default width wasn't updated.\n");
DBG_PRINTF("EmuCreateDeviceProxy: Default width wasn't updated.\n");
if (g_EmuCDPD.HostPresentationParameters.BackBufferWidth == 480)
DbgPrintf(LOG_PREFIX, "EmuCreateDeviceProxy: Default height wasn't updated.\n");
DBG_PRINTF("EmuCreateDeviceProxy: Default height wasn't updated.\n");
}
if(strcmp(szBackBufferFormat, "x1r5g5b5") == 0)
@ -2069,14 +2069,14 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID)
// detect vertex processing capabilities
if((g_D3DCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) && g_EmuCDPD.DeviceType == XTL::D3DDEVTYPE_HAL)
{
DbgPrintf(LOG_PREFIX, "Using hardware vertex processing\n");
DBG_PRINTF("Using hardware vertex processing\n");
g_EmuCDPD.BehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
g_dwVertexShaderUsage = 0;
}
else
{
DbgPrintf(LOG_PREFIX, "Using software vertex processing\n");
DBG_PRINTF("Using software vertex processing\n");
g_EmuCDPD.BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
g_dwVertexShaderUsage = D3DUSAGE_SOFTWAREPROCESSING;
@ -2230,7 +2230,7 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID)
g_pDD7->GetFourCCCodes(&dwCodes, lpCodes);
for(DWORD v=0;v<dwCodes;v++)
{
DbgPrintf(LOG_PREFIX, "FourCC[%d] = %.4s\n", v, (char *)&(lpCodes[v]));
DBG_PRINTF("FourCC[%d] = %.4s\n", v, (char *)&(lpCodes[v]));
// Map known FourCC codes to Xbox Format
int X_Format;
switch (lpCodes[v]) {
@ -2445,7 +2445,7 @@ void CxbxUpdateActiveIndexBuffer
CxbxKrnlCleanup(LOG_PREFIX, "CxbxUpdateActiveIndexBuffer: Could not lock index buffer!");
}
DbgPrintf(LOG_PREFIX, "CxbxUpdateActiveIndexBuffer: Copying %d indices (D3DFMT_INDEX16)\n", IndexCount);
DBG_PRINTF("CxbxUpdateActiveIndexBuffer: Copying %d indices (D3DFMT_INDEX16)\n", IndexCount);
memcpy(pData, pIndexData, IndexCount * sizeof(XTL::INDEX16));
indexBuffer.pHostIndexBuffer->Unlock();
@ -2826,7 +2826,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_LoadVertexShader_4)
// LOG_FUNC_ARG(Handle)
// LOG_FUNC_ARG(Address)
// LOG_FUNC_END;
DbgPrintf(LOG_PREFIX, "D3DDevice_LoadVertexShader_4(Handle : %d Address : %08x);\n", Handle, Address);
DBG_PRINTF("D3DDevice_LoadVertexShader_4(Handle : %d Address : %08x);\n", Handle, Address);
// Handle is always address of an Xbox VertexShader struct, or-ed with 1 (X_D3DFVF_RESERVED0)
// An Xbox VertexShader contains : a 'Vshd' signature, flags, a size, a program (and constants)
@ -3485,7 +3485,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreateVertexShader)
}
}
//DbgPrintf(LOG_PREFIX, "MaxVertexShaderConst = %d\n", g_D3DCaps.MaxVertexShaderConst);
//DBG_PRINTF("MaxVertexShaderConst = %d\n", g_D3DCaps.MaxVertexShaderConst);
if (SUCCEEDED(hRet) && pRecompiledFunction != nullptr)
{
@ -3763,7 +3763,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetTexture_4)
// LOG_FUNC_ARG(Stage)
// LOG_FUNC_ARG(pTexture)
// LOG_FUNC_END;
DbgPrintf(LOG_PREFIX, "D3DDevice_SetTexture_4(Stage : %d pTexture : %08x);\n", Stage, pTexture);
DBG_PRINTF("D3DDevice_SetTexture_4(Stage : %d pTexture : %08x);\n", Stage, pTexture);
// Call the Xbox implementation of this function, to properly handle reference counting for us
//XB_trampoline(VOID, WINAPI, D3DDevice_SetTexture_4, (X_D3DBaseTexture*));
@ -3978,7 +3978,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexData4f)
}
g_InlineVertexBuffer_Table = (struct _D3DIVB*)realloc(g_InlineVertexBuffer_Table, sizeof(struct _D3DIVB) * g_InlineVertexBuffer_TableLength);
DbgPrintf(LOG_PREFIX, "Reallocated g_InlineVertexBuffer_Table to %d entries\n", g_InlineVertexBuffer_TableLength);
DBG_PRINTF("Reallocated g_InlineVertexBuffer_Table to %d entries\n", g_InlineVertexBuffer_TableLength);
}
// Is this the initial call after D3DDevice_Begin() ?
@ -4715,7 +4715,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText
DEBUG_D3DRESULT(hRet, "pHostParentTexture->GetSurfaceLevel");
if (hRet == D3D_OK) {
SetHostSurface(pXboxSurface, pNewHostSurface);
DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created surface level (%u, 0x%.08X, 0x%.08X)\n",
DBG_PRINTF("CreateHostResource : Successfully created surface level (%u, 0x%.08X, 0x%.08X)\n",
SurfaceLevel, pResource, pNewHostSurface);
return;
}
@ -4740,7 +4740,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText
DEBUG_D3DRESULT(hRet, "pParentHostVolumeTexture->GetVolumeLevel");
if (hRet == D3D_OK) {
SetHostVolume(pXboxVolume, pNewHostVolume);
DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created volume level (%u, 0x%.08X, 0x%.08X)\n",
DBG_PRINTF("CreateHostResource : Successfully created volume level (%u, 0x%.08X, 0x%.08X)\n",
VolumeLevel, pResource, pNewHostVolume);
return;
}
@ -4992,9 +4992,9 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText
}
SetHostSurface(pResource, pNewHostSurface);
DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n",
DBG_PRINTF("CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n",
ResourceTypeName, pResource, pNewHostSurface);
DbgPrintf(LOG_PREFIX, "CreateHostResource : Width : %d, Height : %d, Format : %d\n",
DBG_PRINTF("CreateHostResource : Width : %d, Height : %d, Format : %d\n",
dwWidth, dwHeight, PCFormat);
break;
}
@ -5007,7 +5007,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText
// and retrieve and convert all of it's GetVolumeLevel() slices.
pNewHostVolume = nullptr;
// SetHostVolume(pResource, pNewHostVolume);
// DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n",
// DBG_PRINTF("CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n",
// ResourceTypeName, pResource, pNewHostVolume);
break;
}
@ -5061,7 +5061,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText
}
SetHostTexture(pResource, pNewHostTexture);
DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n",
DBG_PRINTF("CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n",
ResourceTypeName, pResource, pNewHostTexture);
break;
}
@ -5079,13 +5079,13 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText
}
SetHostVolumeTexture(pResource, pNewHostVolumeTexture);
DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n",
DBG_PRINTF("CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n",
ResourceTypeName, pResource, pNewHostVolumeTexture);
break;
}
case XTL::X_D3DRTYPE_CUBETEXTURE: {
DbgPrintf(LOG_PREFIX, "CreateCubeTexture(%d, %d, 0, %d, D3DPOOL_MANAGED)\n", dwWidth,
DBG_PRINTF("CreateCubeTexture(%d, %d, 0, %d, D3DPOOL_MANAGED)\n", dwWidth,
dwMipMapLevels, PCFormat);
hRet = g_pD3DDevice->CreateCubeTexture(dwWidth, dwMipMapLevels, D3DUsage,
@ -5103,7 +5103,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText
// TODO : Because cube face surfaces can be used as a render-target,
// we should call SetHostSurface() on all 6 faces, so that when Xbox
// code accesses a face, the host counterpart is already registered!
DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n",
DBG_PRINTF("CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n",
ResourceTypeName, pResource, pNewHostCubeTexture);
break;
}
@ -5189,7 +5189,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText
// Do we need to convert to ARGB?
if (bConvertToARGB) {
DbgPrintf(LOG_PREFIX, "Unsupported texture format, expanding to D3DFMT_A8R8G8B8");
DBG_PRINTF("Unsupported texture format, expanding to D3DFMT_A8R8G8B8");
// Convert a row at a time, using a libyuv-like callback approach :
if (!ConvertD3DTextureToARGBBuffer(
@ -5356,7 +5356,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText
break;
}
DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created %S (0x%.08X, 0x%.08X, 0x%.08X)\n", ResourceTypeName, pResource->Data, pPushBuffer->Size, pPushBuffer->AllocationSize);
DBG_PRINTF("CreateHostResource : Successfully created %S (0x%.08X, 0x%.08X, 0x%.08X)\n", ResourceTypeName, pResource->Data, pPushBuffer->Size, pPushBuffer->AllocationSize);
break;
}
@ -5659,7 +5659,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetTextureState_BorderColor_4)
// LOG_FUNC_ARG(Stage)
// LOG_FUNC_ARG(Value)
// LOG_FUNC_END;
DbgPrintf(LOG_PREFIX, "D3DDevice_SetTextureState_BorderColor_4(Stage : %d Value : %d);\n", Stage, Value);
DBG_PRINTF("D3DDevice_SetTextureState_BorderColor_4(Stage : %d Value : %d);\n", Stage, Value);
HRESULT hRet;
hRet = g_pD3DDevice->SetSamplerState(Stage, D3DSAMP_BORDERCOLOR, Value);
@ -5751,7 +5751,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetTextureState_BumpEnv_8)
// LOG_FUNC_ARG(Type)
// LOG_FUNC_ARG(Value)
// LOG_FUNC_END;
DbgPrintf(LOG_PREFIX, "D3DDevice_SetTextureState_BumpEnv_8(Stage : %d Type : %d Value : %d);\n", Stage, Type, Value);
DBG_PRINTF("D3DDevice_SetTextureState_BumpEnv_8(Stage : %d Type : %d Value : %d);\n", Stage, Type, Value);
HRESULT hRet = D3D_OK;
@ -6087,85 +6087,85 @@ VOID __fastcall XTL::EMUPATCH(D3DDevice_SetRenderState_Simple)
if(OrigValue & (1L<<24))
Value |= D3DCOLORWRITEENABLE_ALPHA;
DbgPrintf(LOG_PREFIX, "D3DRS_COLORWRITEENABLE := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_COLORWRITEENABLE := 0x%.08X\n", Value);
}
break;
case D3DRS_SHADEMODE:
Value = EmuXB2PC_D3DSHADEMODE(Value);
DbgPrintf(LOG_PREFIX, "D3DRS_SHADEMODE := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_SHADEMODE := 0x%.08X\n", Value);
break;
case D3DRS_BLENDOP:
Value = EmuXB2PC_D3DBLENDOP(Value);
DbgPrintf(LOG_PREFIX, "D3DRS_BLENDOP := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_BLENDOP := 0x%.08X\n", Value);
break;
case D3DRS_SRCBLEND:
Value = EmuXB2PC_D3DBLEND(Value);
DbgPrintf(LOG_PREFIX, "D3DRS_SRCBLEND := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_SRCBLEND := 0x%.08X\n", Value);
break;
case D3DRS_DESTBLEND:
Value = EmuXB2PC_D3DBLEND(Value);
DbgPrintf(LOG_PREFIX, "D3DRS_DESTBLEND := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_DESTBLEND := 0x%.08X\n", Value);
break;
case D3DRS_ZFUNC:
Value = EmuXB2PC_D3DCMPFUNC(Value);
DbgPrintf(LOG_PREFIX, "D3DRS_ZFUNC := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_ZFUNC := 0x%.08X\n", Value);
break;
case D3DRS_ALPHAFUNC:
Value = EmuXB2PC_D3DCMPFUNC(Value);
DbgPrintf(LOG_PREFIX, "D3DRS_ALPHAFUNC := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_ALPHAFUNC := 0x%.08X\n", Value);
break;
case D3DRS_ALPHATESTENABLE:
DbgPrintf(LOG_PREFIX, "D3DRS_ALPHATESTENABLE := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_ALPHATESTENABLE := 0x%.08X\n", Value);
break;
case D3DRS_ALPHABLENDENABLE:
DbgPrintf(LOG_PREFIX, "D3DRS_ALPHABLENDENABLE := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_ALPHABLENDENABLE := 0x%.08X\n", Value);
break;
case D3DRS_ALPHAREF:
DbgPrintf(LOG_PREFIX, "D3DRS_ALPHAREF := %lf\n", DWtoF(Value));
DBG_PRINTF("D3DRS_ALPHAREF := %lf\n", DWtoF(Value));
break;
case D3DRS_ZWRITEENABLE:
DbgPrintf(LOG_PREFIX, "D3DRS_ZWRITEENABLE := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_ZWRITEENABLE := 0x%.08X\n", Value);
break;
case D3DRS_DITHERENABLE:
DbgPrintf(LOG_PREFIX, "D3DRS_DITHERENABLE := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_DITHERENABLE := 0x%.08X\n", Value);
break;
case D3DRS_STENCILZFAIL:
Value = EmuXB2PC_D3DSTENCILOP(Value);
DbgPrintf(LOG_PREFIX, "D3DRS_STENCILZFAIL := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_STENCILZFAIL := 0x%.08X\n", Value);
break;
case D3DRS_STENCILPASS:
Value = EmuXB2PC_D3DSTENCILOP(Value);
DbgPrintf(LOG_PREFIX, "D3DRS_STENCILPASS := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_STENCILPASS := 0x%.08X\n", Value);
break;
case D3DRS_STENCILFUNC:
Value = EmuXB2PC_D3DCMPFUNC(Value);
DbgPrintf(LOG_PREFIX, "D3DRS_STENCILFUNC := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_STENCILFUNC := 0x%.08X\n", Value);
break;
case D3DRS_STENCILREF:
DbgPrintf(LOG_PREFIX, "D3DRS_STENCILREF := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_STENCILREF := 0x%.08X\n", Value);
break;
case D3DRS_STENCILMASK:
DbgPrintf(LOG_PREFIX, "D3DRS_STENCILMASK := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_STENCILMASK := 0x%.08X\n", Value);
break;
case D3DRS_STENCILWRITEMASK:
DbgPrintf(LOG_PREFIX, "D3DRS_STENCILWRITEMASK := 0x%.08X\n", Value);
DBG_PRINTF("D3DRS_STENCILWRITEMASK := 0x%.08X\n", Value);
break;
default:
@ -6653,7 +6653,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetStreamSource_4)
// LOG_FUNC_ARG(pStreamData)
// LOG_FUNC_ARG(Stride)
// LOG_FUNC_END;
DbgPrintf(LOG_PREFIX, "D3DDevice_SetStreamSource_4(StreamNumber : %08X pStreamData : %08X Stride : %08X);\n", StreamNumber, pStreamData, Stride);
DBG_PRINTF("D3DDevice_SetStreamSource_4(StreamNumber : %08X pStreamData : %08X Stride : %08X);\n", StreamNumber, pStreamData, Stride);
// Forward to Xbox implementation
// This should stop us having to patch GetStreamSource!
@ -6686,7 +6686,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetStreamSource_8)
// LOG_FUNC_ARG(pStreamData)
// LOG_FUNC_ARG(Stride)
// LOG_FUNC_END;
DbgPrintf(LOG_PREFIX, "D3DDevice_SetStreamSource_8(StreamNumber : %08X pStreamData : %08X Stride : %08X);\n", StreamNumber, pStreamData, Stride);
DBG_PRINTF("D3DDevice_SetStreamSource_8(StreamNumber : %08X pStreamData : %08X Stride : %08X);\n", StreamNumber, pStreamData, Stride);
// Forward to Xbox implementation
// This should stop us having to patch GetStreamSource!
@ -7199,7 +7199,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetPixelShader_0)
//LOG_FUNC_ONE_ARG(Handle);
DbgPrintf(LOG_PREFIX, "D3DDevice_SetPixelShader_0(Handle : %d);\n", Handle);
DBG_PRINTF("D3DDevice_SetPixelShader_0(Handle : %d);\n", Handle);
// Call the Xbox function to make sure D3D structures get set
//XB_trampoline(VOID, WINAPI, D3DDevice_SetPixelShader_0, ());
@ -8934,7 +8934,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetPixelShaderConstant_4)
// LOG_FUNC_ARG(pConstantData)
// LOG_FUNC_ARG(ConstantCount)
// LOG_FUNC_END;
DbgPrintf(LOG_PREFIX, "D3DDevice_SetPixelShaderConstant_4(Register : %d pConstantData : %08X ConstantCount : %d);\n", Register, pConstantData, ConstantCount);
DBG_PRINTF("D3DDevice_SetPixelShaderConstant_4(Register : %d pConstantData : %08X ConstantCount : %d);\n", Register, pConstantData, ConstantCount);
// TODO: This hack is necessary for Vertex Shaders on XDKs prior to 4361, but if this
// causes problems with pixel shaders, feel free to comment out the hack below.

View File

@ -36,6 +36,8 @@
// ******************************************************************
#define _XBOXKRNL_DEFEXTRN_
#define LOG_PREFIX CXBXR_MODULE::D3DCVT
#include "CxbxKrnl/Emu.h"
#include "CxbxKrnl/EmuXTL.h"
#include "XbConvert.h"
@ -1037,7 +1039,7 @@ XTL::D3DFORMAT XTL::EmuXB2PC_D3DFormat(X_D3DFORMAT Format)
{
const FormatInfo *info = &FormatInfos[Format];
if (info->warning != nullptr) {
DbgPrintf(LOG_PREFIX_D3DCVT, "EmuXB2PC_D3DFormat %s\n", info->warning);
DBG_PRINTF("EmuXB2PC_D3DFormat %s\n", info->warning);
}
return info->pc;
@ -1049,7 +1051,7 @@ XTL::D3DFORMAT XTL::EmuXB2PC_D3DFormat(X_D3DFORMAT Format)
case ((X_D3DFORMAT)0xffffffff):
return D3DFMT_UNKNOWN; // TODO -oCXBX: Not sure if this counts as swizzled or not...
default:
CxbxKrnlCleanup(LOG_PREFIX_D3DCVT, "EmuXB2PC_D3DFormat: Unknown Format (0x%.08X)", Format);
CxbxKrnlCleanup(LOG_PREFIX, "EmuXB2PC_D3DFormat: Unknown Format (0x%.08X)", Format);
}
return D3DFMT_UNKNOWN;
@ -1131,7 +1133,7 @@ XTL::X_D3DFORMAT XTL::EmuPC2XB_D3DFormat(D3DFORMAT Format, bool bPreferLinear)
result = X_D3DFMT_VERTEXDATA;
break;
default:
CxbxKrnlCleanup(LOG_PREFIX_D3DCVT, "EmuPC2XB_D3DFormat: Unknown Format (%d)", Format);
CxbxKrnlCleanup(LOG_PREFIX, "EmuPC2XB_D3DFormat: Unknown Format (%d)", Format);
}
return result;
@ -1183,7 +1185,7 @@ XTL::D3DMULTISAMPLE_TYPE XTL::EmuXB2PC_D3DMultiSampleFormat(DWORD Type)
result = D3DMULTISAMPLE_9_SAMPLES;
break;
default:
EmuLog(LOG_PREFIX_D3DCVT, LOG_LEVEL::WARNING, "Unknown Multisample Type (0x%X)!\x0d\x0a.", Type);
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unknown Multisample Type (0x%X)!\x0d\x0a.", Type);
result = D3DMULTISAMPLE_NONE;
}
return result;

View File

@ -90,7 +90,7 @@ typedef uint8_t uint8; // TODO : Remove
#define DbgPshPrintf \
LOG_CHECK_ENABLED(LOG_PREFIX, LOG_LEVEL::DEBUG) \
LOG_CHECK_ENABLED(LOG_LEVEL::DEBUG) \
if(g_bPrintfOn) printf
@ -1613,7 +1613,7 @@ bool PSH_IMD_ARGUMENT::Decode(const DWORD Value, DWORD aMask, TArgumentType Argu
Type = PARAM_EF_PROD;
break;
default :
DbgPrintf(LOG_PREFIX, "INVALID ARGUMENT!\n");
DBG_PRINTF("INVALID ARGUMENT!\n");
Result = false;
}
@ -2261,8 +2261,8 @@ void PSH_XBOX_SHADER::Log(const char *PhaseStr)
{
//if (MayLog(lfUnit))
{
DbgPrintf(LOG_PREFIX, "New decoding - %s :\n", PhaseStr);
DbgPrintf(LOG_PREFIX, "%s\n", ToString().c_str());
DBG_PRINTF("New decoding - %s :\n", PhaseStr);
DBG_PRINTF("%s\n", ToString().c_str());
}
}
@ -2461,7 +2461,7 @@ PSH_RECOMPILED_SHADER PSH_XBOX_SHADER::Decode(XTL::X_D3DPIXELSHADERDEF *pPSDef)
//if (MayLog(LogFlags))
{
// print relevant contents to the debug console
DbgPrintf(LOG_PREFIX, "%s\n", DecodedToString(pPSDef).c_str());
DBG_PRINTF("%s\n", DecodedToString(pPSDef).c_str());
}
// TODO:
@ -3682,7 +3682,7 @@ bool PSH_XBOX_SHADER::RemoveUselessWrites()
if ( (CurArg->Address < MaxTemporaryRegisters)
&& ((RegUsage[CurArg->Type][CurArg->Address] & CurArg->Mask) == 0))
{
DbgPrintf(LOG_PREFIX, "; Removed useless assignment to register %s\n", CurArg->ToString().c_str());
DBG_PRINTF("; Removed useless assignment to register %s\n", CurArg->ToString().c_str());
CurArg->Type = PARAM_DISCARD;
Result = true;
}
@ -3979,7 +3979,7 @@ void PSH_XBOX_SHADER::ConvertXFCToNative(int i)
InsertIntermediate(&Ins, InsertPos);
++InsertPos;
DbgPrintf(LOG_PREFIX, "; Inserted final combiner calculation of V1R0_sum register\n");
DBG_PRINTF("; Inserted final combiner calculation of V1R0_sum register\n");
}
if (NeedsProd)
@ -3991,7 +3991,7 @@ void PSH_XBOX_SHADER::ConvertXFCToNative(int i)
Ins.Parameters[1] = Cur.Parameters[5]; // F
InsertIntermediate(&Ins, InsertPos);
++InsertPos;
DbgPrintf(LOG_PREFIX, "; Inserted final combiner calculation of EF_prod register\n");
DBG_PRINTF("; Inserted final combiner calculation of EF_prod register\n");
}
// The final combiner calculates : r0.rgb=s0*s1 + (1-s0)*s2 + s3
@ -4441,7 +4441,7 @@ bool PSH_XBOX_SHADER::FixArgumentModifiers()
InsertIntermediate(&Ins, InsertPos);
++InsertPos;
++Cur;
DbgPrintf(LOG_PREFIX, "; Used intermediate move to avoid argument modifier\n");
DBG_PRINTF("; Used intermediate move to avoid argument modifier\n");
Result = true;
}
}
@ -4463,7 +4463,7 @@ bool PSH_XBOX_SHADER::FixArgumentModifiers()
Ins.CommentString = "Inserted to avoid constant modifier (applied below on register)";
InsertIntermediate(&Ins, InsertPos);
++InsertPos;
DbgPrintf(LOG_PREFIX, "; Used intermediate move to avoid constant modifier\n");
DBG_PRINTF("; Used intermediate move to avoid constant modifier\n");
Result = true;
}
}
@ -4499,7 +4499,7 @@ bool PSH_XBOX_SHADER::FixConstantParameters()
if (Cur->Parameters[p].SetScaleConstRegister(Cur->Parameters[p].GetConstValue(), Recompiled))
{
DbgPrintf(LOG_PREFIX, "; Replaced constant value with constant register\n");
DBG_PRINTF("; Replaced constant value with constant register\n");
Result = true;
}
}
@ -4539,7 +4539,7 @@ bool PSH_XBOX_SHADER::FixInstructionModifiers()
Ins.Output[0] = Ins.Parameters[0] = Cur->Output[0];
Ins.Parameters[1].SetScaleConstRegister(0.5f, Recompiled);
Ins.CommentString = "; Inserted adjustment by constant register for INST_bias";
DbgPrintf(LOG_PREFIX, "; Inserted adjustment by constant register for INST_bias\n");
DBG_PRINTF("; Inserted adjustment by constant register for INST_bias\n");
break;
}
case INSMOD_X2: // y = x * 2
@ -4553,7 +4553,7 @@ bool PSH_XBOX_SHADER::FixInstructionModifiers()
Ins.Output[0] = Ins.Parameters[0] = Cur->Output[0];
Ins.Parameters[1].SetScaleConstRegister(2.0f, Recompiled);
Ins.CommentString = "; Inserted adjustment by constant register for INST_x2";
DbgPrintf(LOG_PREFIX, "; Inserted adjustment by constant register for INST_x2\n");
DBG_PRINTF("; Inserted adjustment by constant register for INST_x2\n");
break;
}
case INSMOD_BX2: // y = (x - 0.5) * 2 // Xbox only : TODO : Fixup occurrances!
@ -4563,7 +4563,7 @@ bool PSH_XBOX_SHADER::FixInstructionModifiers()
Ins.Parameters[1].SetScaleConstRegister(2.0f, Recompiled);
Ins.Parameters[2].SetScaleConstRegister(-1.0f, Recompiled);
Ins.CommentString = "; Inserted adjustment by constant register for INST_bx2";
DbgPrintf(LOG_PREFIX, "; Inserted adjustment by constant register for INST_bx2\n");
DBG_PRINTF("; Inserted adjustment by constant register for INST_bx2\n");
break;
}
case INSMOD_X4: // y = x * 4
@ -4577,7 +4577,7 @@ bool PSH_XBOX_SHADER::FixInstructionModifiers()
Ins.Output[0] = Ins.Parameters[0] = Cur->Output[0];
Ins.Parameters[1].SetScaleConstRegister(4.0f, Recompiled);
Ins.CommentString = "; Inserted adjustment by constant register for INST_x4";
DbgPrintf(LOG_PREFIX, "; Inserted adjustment by constant register for INST_x4\n");
DBG_PRINTF("; Inserted adjustment by constant register for INST_x4\n");
break;
}
case INSMOD_D2: // y = x * 0.5
@ -4591,7 +4591,7 @@ bool PSH_XBOX_SHADER::FixInstructionModifiers()
Ins.Output[0] = Ins.Parameters[0] = Cur->Output[0];
Ins.Parameters[1].SetScaleConstRegister(0.5f, Recompiled);
Ins.CommentString = "; Inserted adjustment by constant register for INST_d2";
DbgPrintf(LOG_PREFIX, "; Inserted adjustment by constant register for INST_d2\n");
DBG_PRINTF("; Inserted adjustment by constant register for INST_d2\n");
break;
}
case INSMOD_X8: // y = x * 8 // ps 1.4 only
@ -4605,7 +4605,7 @@ bool PSH_XBOX_SHADER::FixInstructionModifiers()
Ins.Output[0] = Ins.Parameters[0] = Cur->Output[0];
Ins.Parameters[1].SetScaleConstRegister(8.0f, Recompiled);
Ins.CommentString = "; Inserted adjustment by constant register for INST_x8";
DbgPrintf(LOG_PREFIX, "; Inserted adjustment by constant register for INST_x8\n");
DBG_PRINTF("; Inserted adjustment by constant register for INST_x8\n");
break;
}
case INSMOD_D4: // y = x * 0.25 // ps 1.4 only
@ -4619,7 +4619,7 @@ bool PSH_XBOX_SHADER::FixInstructionModifiers()
Ins.Output[0] = Ins.Parameters[0] = Cur->Output[0];
Ins.Parameters[1].SetScaleConstRegister(0.25f, Recompiled);
Ins.CommentString = "; Inserted adjustment by constant register for INST_d4";
DbgPrintf(LOG_PREFIX, "; Inserted adjustment by constant register for INST_d4\n");
DBG_PRINTF("; Inserted adjustment by constant register for INST_d4\n");
break;
}
case INSMOD_D8: // y = x * 0.125 // ps 1.4 only
@ -4633,7 +4633,7 @@ bool PSH_XBOX_SHADER::FixInstructionModifiers()
Ins.Output[0] = Ins.Parameters[0] = Cur->Output[0];
Ins.Parameters[1].SetScaleConstRegister(0.125f, Recompiled);
Ins.CommentString = "; Inserted adjustment by constant register for INST_d8";
DbgPrintf(LOG_PREFIX, "; Inserted adjustment by constant register for INST_d8\n");
DBG_PRINTF("; Inserted adjustment by constant register for INST_d8\n");
break;
}
case INSMOD_SAT: // Xbox doesn"t support this, but has ARGMOD_SATURATE instead
@ -4752,7 +4752,7 @@ bool PSH_XBOX_SHADER::CombineInstructions()
Op2->Parameters[2] = Op1->Parameters[0];
DeleteIntermediate(i);
DeleteIntermediate(i);
DbgPrintf(LOG_PREFIX, "; Changed temporary MUL,MUL,CND via MOV,MOV,CND into a single CND\n");
DBG_PRINTF("; Changed temporary MUL,MUL,CND via MOV,MOV,CND into a single CND\n");
Result = true;
continue;
}
@ -4777,7 +4777,7 @@ bool PSH_XBOX_SHADER::CombineInstructions()
Op2->Modifier = Op0->Modifier;
DeleteIntermediate(i);
DeleteIntermediate(i);
DbgPrintf(LOG_PREFIX, "; Changed temporary MUL,MUL,ADD into a single LRP\n");
DBG_PRINTF("; Changed temporary MUL,MUL,ADD into a single LRP\n");
Result = true;
continue;
}
@ -4794,7 +4794,7 @@ bool PSH_XBOX_SHADER::CombineInstructions()
Op2->Modifier = Op0->Modifier;
DeleteIntermediate(i);
DeleteIntermediate(i);
DbgPrintf(LOG_PREFIX, "; Changed temporary MUL,MUL,ADD into a single MAD\n");
DBG_PRINTF("; Changed temporary MUL,MUL,ADD into a single MAD\n");
Result = true;
continue;
}
@ -4809,7 +4809,7 @@ bool PSH_XBOX_SHADER::CombineInstructions()
Op1->Parameters[2] = Op0->Output[0];
// Remove the trailing ADD :
DeleteIntermediate(i+2);
DbgPrintf(LOG_PREFIX, "; Changed temporary MUL,MUL,ADD into a MUL,MAD\n");
DBG_PRINTF("; Changed temporary MUL,MUL,ADD into a MUL,MAD\n");
Result = true;
continue;
}
@ -4826,7 +4826,7 @@ bool PSH_XBOX_SHADER::CombineInstructions()
Op2->Parameters[1] = Op1->Parameters[0];
DeleteIntermediate(i);
DeleteIntermediate(i);
DbgPrintf(LOG_PREFIX, "; Changed temporary MUL,MUL,ADD into a MUL\n");
DBG_PRINTF("; Changed temporary MUL,MUL,ADD into a MUL\n");
Result = true;
continue;
}
@ -4851,7 +4851,7 @@ bool PSH_XBOX_SHADER::CombineInstructions()
Op0->Opcode = PO_MAD;
Op0->Parameters[2] = Op1->Parameters[1];
DeleteIntermediate(i+1);
DbgPrintf(LOG_PREFIX, "; Changed MUL,ADD into a single MAD\n");
DBG_PRINTF("; Changed MUL,ADD into a single MAD\n");
Result = true;
continue;
}
@ -4936,7 +4936,7 @@ bool PSH_XBOX_SHADER::CombineInstructions()
if (CanOptimize)
{
DeleteIntermediate(i);
DbgPrintf(LOG_PREFIX, "; Moved MOV input into following instructions\n3");
DBG_PRINTF("; Moved MOV input into following instructions\n3");
Result = true;
}
}
@ -4956,7 +4956,7 @@ bool PSH_XBOX_SHADER::CombineInstructions()
// > mul r0.rgb, r0,t0
Op0->Output[0] = Op1->Output[0];
DeleteIntermediate(i+1);
DbgPrintf(LOG_PREFIX, "; Changed temporary MUL,MOV into a MUL\n");
DBG_PRINTF("; Changed temporary MUL,MOV into a MUL\n");
Result = true;
continue;
}
@ -4969,7 +4969,7 @@ bool PSH_XBOX_SHADER::CombineInstructions()
if (IsRegisterFreeFromIndexOnwards(i, PARAM_R, 1))
{
ReplaceRegisterFromIndexOnwards(i, Op0->Output[0].Type, Op0->Output[0].Address, PARAM_R, 1);
DbgPrintf(LOG_PREFIX, "; Changed fake register by r1\n");
DBG_PRINTF("; Changed fake register by r1\n");
Result = true;
continue;
}
@ -4997,7 +4997,7 @@ bool PSH_XBOX_SHADER::SimplifyMOV(PPSH_INTERMEDIATE_FORMAT Cur)
if (CanSimplify)
{
Cur->Opcode = PO_NOP; // This nop will be removed in a recursive fixup
DbgPrintf(LOG_PREFIX, "; Changed MOV into a NOP\n");
DBG_PRINTF("; Changed MOV into a NOP\n");
return true;
}
}
@ -5015,11 +5015,11 @@ bool PSH_XBOX_SHADER::SimplifyMOV(PPSH_INTERMEDIATE_FORMAT Cur)
Cur->Parameters[0].Address = 0;
Cur->Parameters[0].Modifiers = 0;
Cur->Parameters[1] = Cur->Parameters[0];
DbgPrintf(LOG_PREFIX, "; Changed MOV 0 into a SUB v0,v0\n");
DBG_PRINTF("; Changed MOV 0 into a SUB v0,v0\n");
}
else
{
DbgPrintf(LOG_PREFIX, "; Changed MOV 0 into a MOV c0\n");
DBG_PRINTF("; Changed MOV 0 into a MOV c0\n");
}
return true;
@ -5060,11 +5060,11 @@ bool PSH_XBOX_SHADER::SimplifyMOV(PPSH_INTERMEDIATE_FORMAT Cur)
// Try to simulate all factors (0.5, 1.0 and 2.0) using an output modifier :
Cur->ScaleOutput(Factor);
DbgPrintf(LOG_PREFIX, "; Changed MOV {const} into a SUB_factor 1-v0,-v0\n");
DBG_PRINTF("; Changed MOV {const} into a SUB_factor 1-v0,-v0\n");
}
else
{
DbgPrintf(LOG_PREFIX, "; Changed MOV {const} into a MOV c#\n");
DBG_PRINTF("; Changed MOV {const} into a MOV c#\n");
}
return true;
}
@ -5078,7 +5078,7 @@ bool PSH_XBOX_SHADER::SimplifyADD(PPSH_INTERMEDIATE_FORMAT Cur)
{
// Change it into a MOV (the first argument is already in-place)
Cur->Opcode = PO_MOV;
DbgPrintf(LOG_PREFIX, "; Changed ADD s0,0 into a MOV s0\n");
DBG_PRINTF("; Changed ADD s0,0 into a MOV s0\n");
return true;
}
return false;
@ -5093,7 +5093,7 @@ bool PSH_XBOX_SHADER::SimplifyMAD(PPSH_INTERMEDIATE_FORMAT Cur, int index)
// Change it into s2 :
Cur->Opcode = PO_MOV;
Cur->Parameters[0] = Cur->Parameters[2];
DbgPrintf(LOG_PREFIX, "; Changed MAD s0,0 into a MOV s0\n");
DBG_PRINTF("; Changed MAD s0,0 into a MOV s0\n");
return true;
}
@ -5102,7 +5102,7 @@ bool PSH_XBOX_SHADER::SimplifyMAD(PPSH_INTERMEDIATE_FORMAT Cur, int index)
{
// Change it into s0*s1 :
Cur->Opcode = PO_MUL;
DbgPrintf(LOG_PREFIX, "; Changed MAD s0, s1,0 into a MUL s0, s1\n");
DBG_PRINTF("; Changed MAD s0, s1,0 into a MUL s0, s1\n");
return true;
}
@ -5112,7 +5112,7 @@ bool PSH_XBOX_SHADER::SimplifyMAD(PPSH_INTERMEDIATE_FORMAT Cur, int index)
// Change it into s0+s2 :
Cur->Opcode = PO_ADD;
Cur->Parameters[1] = Cur->Parameters[2];
DbgPrintf(LOG_PREFIX, "; Changed MAD s0,1,s2 into a ADD s0,s2\n");
DBG_PRINTF("; Changed MAD s0,1,s2 into a ADD s0,s2\n");
return true;
}
@ -5123,7 +5123,7 @@ bool PSH_XBOX_SHADER::SimplifyMAD(PPSH_INTERMEDIATE_FORMAT Cur, int index)
Cur->Opcode = PO_SUB;
Cur->Parameters[1] = Cur->Parameters[0];
Cur->Parameters[0] = Cur->Parameters[2];
DbgPrintf(LOG_PREFIX, "; Changed MAD s0,-1,s2 into a SUB s2,s0\n");
DBG_PRINTF("; Changed MAD s0,-1,s2 into a SUB s2,s0\n");
return true;
}
@ -5144,11 +5144,11 @@ bool PSH_XBOX_SHADER::SimplifyMAD(PPSH_INTERMEDIATE_FORMAT Cur, int index)
Ins.Output[0] = Ins.Parameters[0] = Cur->Parameters[1];
Ins.CommentString = "; Inserted to perform division by 2";
InsertIntermediate(&Ins, index);
DbgPrintf(LOG_PREFIX, "; Changed MAD 0.5,s1,s2 into a MOV_d2 s1, s1 ADD s1, s2\n");
DBG_PRINTF("; Changed MAD 0.5,s1,s2 into a MOV_d2 s1, s1 ADD s1, s2\n");
}
else
{
DbgPrintf(LOG_PREFIX, "; Changed MAD 0.5,s1,s2 into a MAD c#,s1,s2\n");
DBG_PRINTF("; Changed MAD 0.5,s1,s2 into a MAD c#,s1,s2\n");
}
return true;
}
@ -5168,11 +5168,11 @@ bool PSH_XBOX_SHADER::SimplifyMAD(PPSH_INTERMEDIATE_FORMAT Cur, int index)
Ins.Output[0] = Ins.Parameters[0] = Cur->Parameters[0];
Ins.CommentString = "; Inserted to perform division by 2";
InsertIntermediate(&Ins, index);
DbgPrintf(LOG_PREFIX, "; Changed MAD s0,0.5,s2 into a MOV_d2 s0, s0 ADD s0, s2\n");
DBG_PRINTF("; Changed MAD s0,0.5,s2 into a MOV_d2 s0, s0 ADD s0, s2\n");
}
else
{
DbgPrintf(LOG_PREFIX, "; Changed MAD s0,0.5,s2 into a MAD s0,c#,s2\n");
DBG_PRINTF("; Changed MAD s0,0.5,s2 into a MAD s0,c#,s2\n");
}
return true;
}
@ -5186,7 +5186,7 @@ bool PSH_XBOX_SHADER::SimplifySUB(PPSH_INTERMEDIATE_FORMAT Cur)
{
// Change it into a MOV (the first argument is already in-place)
Cur->Opcode = PO_MOV;
DbgPrintf(LOG_PREFIX, "; Changed SUB x, 0 into a MOV x\n");
DBG_PRINTF("; Changed SUB x, 0 into a MOV x\n");
return true;
}
return false;
@ -5200,7 +5200,7 @@ bool PSH_XBOX_SHADER::SimplifyMUL(PPSH_INTERMEDIATE_FORMAT Cur)
// Change it into a MOV (the 0 argument will be resolve in a recursive MOV fixup) :
Cur->Opcode = PO_MOV;
Cur->Parameters[0].SetConstValue(0.0);
DbgPrintf(LOG_PREFIX, "; Changed MUL s0,0 into a MOV 0\n");
DBG_PRINTF("; Changed MUL s0,0 into a MOV 0\n");
return true;
}
@ -5210,7 +5210,7 @@ bool PSH_XBOX_SHADER::SimplifyMUL(PPSH_INTERMEDIATE_FORMAT Cur)
// Change it into a simple MOV and scale the output instead :
Cur->Opcode = PO_MOV;
Cur->ScaleOutput(Cur->Parameters[1].GetConstValue());
DbgPrintf(LOG_PREFIX, "; Changed MUL s0,{const} into a MOV_factor s0\n");
DBG_PRINTF("; Changed MUL s0,{const} into a MOV_factor s0\n");
return true;
}
return false;
@ -5225,7 +5225,7 @@ bool PSH_XBOX_SHADER::SimplifyLRP(PPSH_INTERMEDIATE_FORMAT Cur, int index)
{
// Change it into a MUL (calculating the left part : s0*s1 :
Cur->Opcode = PO_MUL;
DbgPrintf(LOG_PREFIX, "; Changed LRP s0,s1,s2 (where (1-s0)*s2=0) into a MUL s0,s1\n");
DBG_PRINTF("; Changed LRP s0,s1,s2 (where (1-s0)*s2=0) into a MUL s0,s1\n");
return true;
}
@ -5236,7 +5236,7 @@ bool PSH_XBOX_SHADER::SimplifyLRP(PPSH_INTERMEDIATE_FORMAT Cur, int index)
Cur->Opcode = PO_MUL;
Cur->Parameters[0].Invert();
Cur->Parameters[1] = Cur->Parameters[2];
DbgPrintf(LOG_PREFIX, "; Changed LRP s0,s1,s2 (where s0*s1=0) into a MUL (1-s0),s2\n");
DBG_PRINTF("; Changed LRP s0,s1,s2 (where s0*s1=0) into a MUL (1-s0),s2\n");
return true;
}
@ -5247,7 +5247,7 @@ bool PSH_XBOX_SHADER::SimplifyLRP(PPSH_INTERMEDIATE_FORMAT Cur, int index)
Cur->Opcode = PO_MAD;
Cur->Parameters[2] = Cur->Parameters[0];
Cur->Parameters[2].Invert();
DbgPrintf(LOG_PREFIX, "; Changed LRP s0,s1,1 into a MAD s0,s1,1-s0\n");
DBG_PRINTF("; Changed LRP s0,s1,1 into a MAD s0,s1,1-s0\n");
return true;
}
@ -5258,7 +5258,7 @@ bool PSH_XBOX_SHADER::SimplifyLRP(PPSH_INTERMEDIATE_FORMAT Cur, int index)
Cur->Opcode = PO_MAD;
Cur->Parameters[1] = Cur->Parameters[2];
Cur->Parameters[1].Invert();
DbgPrintf(LOG_PREFIX, "; Changed LRP s0,1,s2 into a MAD s0,1-s2,s2\n");
DBG_PRINTF("; Changed LRP s0,1,s2 into a MAD s0,1-s2,s2\n");
return true;
}
@ -5285,7 +5285,7 @@ bool PSH_XBOX_SHADER::SimplifyLRP(PPSH_INTERMEDIATE_FORMAT Cur, int index)
Ins.Parameters[0].SetRegister(Cur->Output[0].Type, Cur->Output[0].Address, 0);
Ins.CommentString = "; Inserted to avoid LRP parameters referencing the output register";
InsertIntermediate(&Ins, index);
DbgPrintf(LOG_PREFIX, "; Changed LRP s0,1,s2 into a MAD s0,1-s2,s2\n");
DBG_PRINTF("; Changed LRP s0,1,s2 into a MAD s0,1-s2,s2\n");
return true;
}
}
@ -5313,7 +5313,7 @@ bool PSH_XBOX_SHADER::FixupCND(PPSH_INTERMEDIATE_FORMAT Cur, int index)
std::swap(Cur->Parameters[1], Cur->Parameters[2]);
Ins.CommentString = Cur->CommentString = "; Changed CND into SUB CMP";
InsertIntermediate(&Ins, index);
DbgPrintf(LOG_PREFIX, "; Changed CND into SUB CMP\n");
DBG_PRINTF("; Changed CND into SUB CMP\n");
return true;
}
@ -6540,7 +6540,7 @@ inline void HandleInputOutput
// 6928: check this as I doubt whether it works really like that
/*if(strcmp(szInput[i], "r1")==0)
{
// DbgPrintf(LOG_PREFIX, "channel: %s\n", szChannels[i]);
// DBG_PRINTF("channel: %s\n", szChannels[i]);
// Sleep(3000);
if((strcmp(szChannels[i], ".a")==0) && (!bR1AWritten)) {
@ -6745,7 +6745,7 @@ inline void HandleInputOutput
//EmuWarningMsg("THIS IS WRONG, FIX ME!");
//if(!szOutput[1][0])
// strcpy(szOut1, szOutput[2]);
DbgPrintf(LOG_PREFIX, "(!szOutput[0][0] || !szOutput[1][0]) && szOutput[2][0] = TRUE!\n");
DBG_PRINTF("(!szOutput[0][0] || !szOutput[1][0]) && szOutput[2][0] = TRUE!\n");
BOOL bUsable=TRUE;
for(i=2; i<4; i++)
@ -6759,7 +6759,7 @@ inline void HandleInputOutput
strcpy(szOut, szOutput[2]);
DbgPrintf(LOG_PREFIX, "BUsable = TRUE, new output: %s\n", szOut);
DBG_PRINTF("BUsable = TRUE, new output: %s\n", szOut);
}
else {

View File

@ -800,7 +800,7 @@ VOID XTL::EmuFlushIVB()
bool bFVF = VshHandleIsFVF(g_CurrentXboxVertexShaderHandle);
DWORD dwCurFVF = (bFVF) ? g_CurrentXboxVertexShaderHandle : g_InlineVertexBuffer_FVF;
DbgPrintf(LOG_PREFIX, "g_InlineVertexBuffer_TableOffset := %d\n", g_InlineVertexBuffer_TableOffset);
DBG_PRINTF("g_InlineVertexBuffer_TableOffset := %d\n", g_InlineVertexBuffer_TableOffset);
// Check the given FVF
switch (dwCurFVF & D3DFVF_POSITION_MASK) {
@ -852,34 +852,34 @@ VOID XTL::EmuFlushIVB()
*pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Position.z;
if (dwPos == D3DFVF_XYZRHW) {
*pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Rhw;
DbgPrintf(LOG_PREFIX, "IVB Position := {%f, %f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Position.x, g_InlineVertexBuffer_Table[v].Position.y, g_InlineVertexBuffer_Table[v].Position.z, g_InlineVertexBuffer_Table[v].Rhw);
DBG_PRINTF("IVB Position := {%f, %f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Position.x, g_InlineVertexBuffer_Table[v].Position.y, g_InlineVertexBuffer_Table[v].Position.z, g_InlineVertexBuffer_Table[v].Rhw);
}
else { // XYZRHW cannot be combined with NORMAL, but the other XYZ formats can :
switch (dwPos) {
case D3DFVF_XYZ:
DbgPrintf(LOG_PREFIX, "IVB Position := {%f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Position.x, g_InlineVertexBuffer_Table[v].Position.y, g_InlineVertexBuffer_Table[v].Position.z);
DBG_PRINTF("IVB Position := {%f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Position.x, g_InlineVertexBuffer_Table[v].Position.y, g_InlineVertexBuffer_Table[v].Position.z);
break;
case D3DFVF_XYZB1:
*pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Blend[0];
DbgPrintf(LOG_PREFIX, "IVB Position := {%f, %f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Position.x, g_InlineVertexBuffer_Table[v].Position.y, g_InlineVertexBuffer_Table[v].Position.z, g_InlineVertexBuffer_Table[v].Blend[0]);
DBG_PRINTF("IVB Position := {%f, %f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Position.x, g_InlineVertexBuffer_Table[v].Position.y, g_InlineVertexBuffer_Table[v].Position.z, g_InlineVertexBuffer_Table[v].Blend[0]);
break;
case D3DFVF_XYZB2:
*pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Blend[0];
*pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Blend[1];
DbgPrintf(LOG_PREFIX, "IVB Position := {%f, %f, %f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Position.x, g_InlineVertexBuffer_Table[v].Position.y, g_InlineVertexBuffer_Table[v].Position.z, g_InlineVertexBuffer_Table[v].Blend[0], g_InlineVertexBuffer_Table[v].Blend[1]);
DBG_PRINTF("IVB Position := {%f, %f, %f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Position.x, g_InlineVertexBuffer_Table[v].Position.y, g_InlineVertexBuffer_Table[v].Position.z, g_InlineVertexBuffer_Table[v].Blend[0], g_InlineVertexBuffer_Table[v].Blend[1]);
break;
case D3DFVF_XYZB3:
*pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Blend[0];
*pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Blend[1];
*pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Blend[2];
DbgPrintf(LOG_PREFIX, "IVB Position := {%f, %f, %f, %f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Position.x, g_InlineVertexBuffer_Table[v].Position.y, g_InlineVertexBuffer_Table[v].Position.z, g_InlineVertexBuffer_Table[v].Blend[0], g_InlineVertexBuffer_Table[v].Blend[1], g_InlineVertexBuffer_Table[v].Blend[2]);
DBG_PRINTF("IVB Position := {%f, %f, %f, %f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Position.x, g_InlineVertexBuffer_Table[v].Position.y, g_InlineVertexBuffer_Table[v].Position.z, g_InlineVertexBuffer_Table[v].Blend[0], g_InlineVertexBuffer_Table[v].Blend[1], g_InlineVertexBuffer_Table[v].Blend[2]);
break;
case D3DFVF_XYZB4:
*pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Blend[0];
*pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Blend[1];
*pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Blend[2];
*pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Blend[3];
DbgPrintf(LOG_PREFIX, "IVB Position := {%f, %f, %f, %f, %f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Position.x, g_InlineVertexBuffer_Table[v].Position.y, g_InlineVertexBuffer_Table[v].Position.z, g_InlineVertexBuffer_Table[v].Blend[0], g_InlineVertexBuffer_Table[v].Blend[1], g_InlineVertexBuffer_Table[v].Blend[2], g_InlineVertexBuffer_Table[v].Blend[3]);
DBG_PRINTF("IVB Position := {%f, %f, %f, %f, %f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Position.x, g_InlineVertexBuffer_Table[v].Position.y, g_InlineVertexBuffer_Table[v].Position.z, g_InlineVertexBuffer_Table[v].Blend[0], g_InlineVertexBuffer_Table[v].Blend[1], g_InlineVertexBuffer_Table[v].Blend[2], g_InlineVertexBuffer_Table[v].Blend[3]);
break;
default:
CxbxKrnlCleanup(LOG_PREFIX, "Unsupported Position Mask (FVF := 0x%.08X dwPos := 0x%.08X)", dwCurFVF, dwPos);
@ -890,25 +890,25 @@ VOID XTL::EmuFlushIVB()
*pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Normal.x;
*pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Normal.y;
*pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Normal.z;
DbgPrintf(LOG_PREFIX, "IVB Normal := {%f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Normal.x, g_InlineVertexBuffer_Table[v].Normal.y, g_InlineVertexBuffer_Table[v].Normal.z);
DBG_PRINTF("IVB Normal := {%f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Normal.x, g_InlineVertexBuffer_Table[v].Normal.y, g_InlineVertexBuffer_Table[v].Normal.z);
}
}
#if 0 // TODO : Was this supported on Xbox from some point in time (pun intended)?
if (dwCurFVF & D3DFVF_PSIZE) {
*(DWORD*)pVertexBufferData++ = g_InlineVertexBuffer_Table[v].PointSize;
DbgPrintf(LOG_PREFIX, "IVB PointSize := 0x%.08X\n", g_InlineVertexBuffer_Table[v].PointSize);
DBG_PRINTF("IVB PointSize := 0x%.08X\n", g_InlineVertexBuffer_Table[v].PointSize);
}
#endif
if (dwCurFVF & D3DFVF_DIFFUSE) {
*(DWORD*)pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Diffuse;
DbgPrintf(LOG_PREFIX, "IVB Diffuse := 0x%.08X\n", g_InlineVertexBuffer_Table[v].Diffuse);
DBG_PRINTF("IVB Diffuse := 0x%.08X\n", g_InlineVertexBuffer_Table[v].Diffuse);
}
if (dwCurFVF & D3DFVF_SPECULAR) {
*(DWORD*)pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Specular;
DbgPrintf(LOG_PREFIX, "IVB Specular := 0x%.08X\n", g_InlineVertexBuffer_Table[v].Specular);
DBG_PRINTF("IVB Specular := 0x%.08X\n", g_InlineVertexBuffer_Table[v].Specular);
}
for (uint i = 0; i < dwTexN; i++) {
@ -925,10 +925,10 @@ VOID XTL::EmuFlushIVB()
if (g_bPrintfOn) {
switch (TexSize[i]) {
case 1: DbgPrintf(LOG_PREFIX, "IVB TexCoord%d := {%f}\n", i + 1, g_InlineVertexBuffer_Table[v].TexCoord[i].x); break;
case 2: DbgPrintf(LOG_PREFIX, "IVB TexCoord%d := {%f, %f}\n", i + 1, g_InlineVertexBuffer_Table[v].TexCoord[i].x, g_InlineVertexBuffer_Table[v].TexCoord[i].y); break;
case 3: DbgPrintf(LOG_PREFIX, "IVB TexCoord%d := {%f, %f, %f}\n", i + 1, g_InlineVertexBuffer_Table[v].TexCoord[i].x, g_InlineVertexBuffer_Table[v].TexCoord[i].y, g_InlineVertexBuffer_Table[v].TexCoord[i].z); break;
case 4: DbgPrintf(LOG_PREFIX, "IVB TexCoord%d := {%f, %f, %f, %f}\n", i + 1, g_InlineVertexBuffer_Table[v].TexCoord[i].x, g_InlineVertexBuffer_Table[v].TexCoord[i].y, g_InlineVertexBuffer_Table[v].TexCoord[i].z, g_InlineVertexBuffer_Table[v].TexCoord[i].w); break;
case 1: DBG_PRINTF("IVB TexCoord%d := {%f}\n", i + 1, g_InlineVertexBuffer_Table[v].TexCoord[i].x); break;
case 2: DBG_PRINTF("IVB TexCoord%d := {%f, %f}\n", i + 1, g_InlineVertexBuffer_Table[v].TexCoord[i].x, g_InlineVertexBuffer_Table[v].TexCoord[i].y); break;
case 3: DBG_PRINTF("IVB TexCoord%d := {%f, %f, %f}\n", i + 1, g_InlineVertexBuffer_Table[v].TexCoord[i].x, g_InlineVertexBuffer_Table[v].TexCoord[i].y, g_InlineVertexBuffer_Table[v].TexCoord[i].z); break;
case 4: DBG_PRINTF("IVB TexCoord%d := {%f, %f, %f, %f}\n", i + 1, g_InlineVertexBuffer_Table[v].TexCoord[i].x, g_InlineVertexBuffer_Table[v].TexCoord[i].y, g_InlineVertexBuffer_Table[v].TexCoord[i].z, g_InlineVertexBuffer_Table[v].TexCoord[i].w); break;
}
}
}

View File

@ -53,7 +53,7 @@
#endif
#define DbgVshPrintf \
LOG_CHECK_ENABLED(LOG_PREFIX, LOG_LEVEL::DEBUG) \
LOG_CHECK_ENABLED(LOG_LEVEL::DEBUG) \
if(g_bPrintfOn) printf
// ****************************************************************************

View File

@ -984,7 +984,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateBuffer)
GeneratePCMFormat(DSBufferDesc, pdsbd->lpwfxFormat, (*ppBuffer)->EmuFlags, pdsbd->dwBufferBytes, &(*ppBuffer)->X_BufferCache, (*ppBuffer)->X_BufferCacheSize);
(*ppBuffer)->EmuBufferDesc = DSBufferDesc;
DbgPrintf(LOG_PREFIX, "DirectSoundCreateBuffer, *ppBuffer := 0x%08X, bytes := 0x%08X\n", *ppBuffer, (*ppBuffer)->EmuBufferDesc.dwBufferBytes);
DBG_PRINTF("DirectSoundCreateBuffer, *ppBuffer := 0x%08X, bytes := 0x%08X\n", *ppBuffer, (*ppBuffer)->EmuBufferDesc.dwBufferBytes);
DSoundBufferCreate(&DSBufferDesc, (*ppBuffer)->EmuDirectSoundBuffer8);
if (pdsbd->dwFlags & DSBCAPS_CTRL3D) {
@ -1798,7 +1798,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateStream)
(*ppStream)->Xb_lpvContext = pdssd->lpvContext;
//TODO: Implement mixbin variable support. Or just merge pdssd struct into DS Stream class.
DbgPrintf(LOG_PREFIX, "DirectSoundCreateStream, *ppStream := 0x%.08X\n", *ppStream);
DBG_PRINTF("DirectSoundCreateStream, *ppStream := 0x%.08X\n", *ppStream);
DSoundBufferCreate(&DSBufferDesc, (*ppStream)->EmuDirectSoundBuffer8);
if (DSBufferDesc.dwFlags & DSBCAPS_CTRL3D) {
@ -3347,7 +3347,7 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSound_GetCaps)
pDSCaps->dwFree2DBuffers = (pDSCaps->dwFreeBufferSGEs == 0 ? 0 : 0x200 /* TODO: Replace me to g_dwFree2DBuffers*/ );
pDSCaps->dwFree3DBuffers = (pDSCaps->dwFreeBufferSGEs == 0 ? 0 : 0x200 /* TODO: Replace me to g_dwFree3DBuffers*/ );
DbgPrintf(LOG_PREFIX, "X_DSCAPS: dwFree2DBuffers = %8X | dwFree3DBuffers = %8X | dwFreeBufferSGEs = %08X | dwMemAlloc = %08X\n", pDSCaps->dwFree2DBuffers, pDSCaps->dwFree3DBuffers, pDSCaps->dwFreeBufferSGEs, pDSCaps->dwMemoryAllocated);
DBG_PRINTF("X_DSCAPS: dwFree2DBuffers = %8X | dwFree3DBuffers = %8X | dwFreeBufferSGEs = %08X | dwMemAlloc = %08X\n", pDSCaps->dwFree2DBuffers, pDSCaps->dwFree3DBuffers, pDSCaps->dwFreeBufferSGEs, pDSCaps->dwMemoryAllocated);
}
leaveCriticalSection;

View File

@ -99,7 +99,7 @@ inline void XADPCM2PCMFormat(LPWAVEFORMATEX lpwfxFormat)
{
#if 0 //For testing purpose if XADPCM to PCM is not accurate.
DbgPrintf(LOG_PREFIX, "EmuDSound: XADPCM WAVEFORMATEX\n"
DBG_PRINTF("EmuDSound: XADPCM WAVEFORMATEX\n"
"{\n"
" wFormatTag : 0x%.04hX\n"
" nChannels : 0x%.02hd\n"
@ -141,7 +141,7 @@ inline void XADPCM2PCMFormat(LPWAVEFORMATEX lpwfxFormat)
#endif
#if 0 //For testing purpose if XADPCM to PCM is not accurate.
DbgPrintf(LOG_PREFIX, "EmuDSound: Converted to PCM WAVEFORMATEX\n"
DBG_PRINTF("EmuDSound: Converted to PCM WAVEFORMATEX\n"
"{\n"
" wFormatTag : 0x%.04hX\n"
" nChannels : 0x%.02hd\n"

View File

@ -1058,7 +1058,7 @@ DWORD WINAPI XTL::EMUPATCH(XInputGetState)
if((dwPort >= 0) && (dwPort <= total_xinput_gamepad))
{
DbgPrintf(LOG_PREFIX, "EmuXInputGetState(): dwPort = %d\n", dwPort );
DBG_PRINTF("EmuXInputGetState(): dwPort = %d\n", dwPort );
//for xinput, we query the state corresponds to port.
if (g_XInputEnabled) {

View File

@ -53,7 +53,7 @@ namespace xboxkrnl
#include "CxbxKrnl\Emu.h"
#include "CxbxKrnl\EmuKrnl.h"
#include "EmuNVNet.h"
#include "EmuNVNet.h"
#include "Logging.h"
// NVNET Register Definitions
@ -394,7 +394,7 @@ void EmuNVNet_UpdateIRQ()
{
if (EmuNVNet_GetRegister(NvRegIrqMask, 4) &&
EmuNVNet_GetRegister(NvRegIrqStatus, 4)) {
DbgPrintf(LOG_PREFIX, "Asserting IRQ\n");
DBG_PRINTF("Asserting IRQ\n");
HalSystemInterrupts[4].Assert(true);
} else {
HalSystemInterrupts[4].Assert(false);
@ -413,7 +413,7 @@ int EmuNVNet_MiiReadWrite(uint64_t val)
reg = mii_ctl & ((1 << NVREG_MIICTL_ADDRSHIFT) - 1);
write = mii_ctl & NVREG_MIICTL_WRITE;
DbgPrintf(LOG_PREFIX, "nvnet mii %s: phy 0x%x %s [0x%x]\n", write ? "write" : "read", phy_addr, EmuNVNet_GetMiiRegisterName(reg), reg);
DBG_PRINTF("nvnet mii %s: phy 0x%x %s [0x%x]\n", write ? "write" : "read", phy_addr, EmuNVNet_GetMiiRegisterName(reg), reg);
if (phy_addr != 1) {
return -1;
@ -444,7 +444,7 @@ int EmuNVNet_MiiReadWrite(uint64_t val)
uint32_t EmuNVNet_Read(xbaddr addr, int size)
{
DbgPrintf(LOG_PREFIX, "Read%d: %s (0x%.8X)\n", size, EmuNVNet_GetRegisterName(addr), addr);
DBG_PRINTF("Read%d: %s (0x%.8X)\n", size, EmuNVNet_GetRegisterName(addr), addr);
switch (addr) {
case NvRegMIIData:
@ -471,7 +471,7 @@ void EmuNVNet_Write(xbaddr addr, uint32_t value, int size)
break;
case NvRegTxRxControl:
if (value == NVREG_TXRXCTL_KICK) {
DbgPrintf(LOG_PREFIX, "NvRegTxRxControl = NVREG_TXRXCTL_KICK!\n");
DBG_PRINTF("NvRegTxRxControl = NVREG_TXRXCTL_KICK!\n");
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "TODO: nvnet_dma_packet_from_guest");
// nvnet_dma_packet_from_guest(s);
}
@ -508,7 +508,7 @@ void EmuNVNet_Write(xbaddr addr, uint32_t value, int size)
break;
}
DbgPrintf(LOG_PREFIX, "Write%d: %s (0x%.8X) = 0x%.8X\n", size, EmuNVNet_GetRegisterName(addr), addr, value);
DBG_PRINTF("Write%d: %s (0x%.8X) = 0x%.8X\n", size, EmuNVNet_GetRegisterName(addr), addr, value);
}
/* NVNetDevice */

View File

@ -53,7 +53,7 @@ namespace xboxkrnl
void SetLEDSequence(LED::Sequence aLEDSequence)
{
// See http://xboxdevwiki.net/PIC#The_LED
DbgPrintf(LOG_PREFIX, "SetLEDSequence : %u\n", (byte)aLEDSequence);
DBG_PRINTF("SetLEDSequence : %u\n", (byte)aLEDSequence);
union {
UINT LedSequenceBlock;

View File

@ -1,78 +1,78 @@
// 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->devices->usb->Hub.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) 2018 ergo720
// *
// * All rights reserved
// *
// ******************************************************************
#define _XBOXKRNL_DEFEXTRN_
#define LOG_PREFIX CXBXR_MODULE::HUB
// 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->devices->usb->Hub.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) 2018 ergo720
// *
// * All rights reserved
// *
// ******************************************************************
#define _XBOXKRNL_DEFEXTRN_
#define LOG_PREFIX CXBXR_MODULE::HUB
// prevent name collisions
namespace xboxkrnl
{
#include <xboxkrnl/xboxkrnl.h> // For PKINTERRUPT, etc.
};
#include "OHCI.h"
#include "Hub.h"
#include "CxbxKrnl\EmuKrnl.h" // For EmuLog
#include "Logging.h"
#define NUM_PORTS 8
};
#include "OHCI.h"
#include "Hub.h"
#include "CxbxKrnl\EmuKrnl.h" // For EmuLog
#include "Logging.h"
#define NUM_PORTS 8
#define PORT_STAT_CONNECTION 0x0001
#define PORT_STAT_ENABLE 0x0002
#define PORT_STAT_SUSPEND 0x0004
#define PORT_STAT_OVERCURRENT 0x0008
#define PORT_STAT_RESET 0x0010
#define PORT_STAT_POWER 0x0100
#define PORT_STAT_LOW_SPEED 0x0200
#define PORT_STAT_LOW_SPEED 0x0200
#define PORT_STAT_C_CONNECTION 0x0001
#define PORT_STAT_C_ENABLE 0x0002
#define PORT_STAT_C_SUSPEND 0x0004
#define PORT_STAT_C_OVERCURRENT 0x0008
#define PORT_STAT_C_RESET 0x0010
#define PORT_STAT_C_RESET 0x0010
#define ClearHubFeature (0x2000 | USB_REQ_CLEAR_FEATURE)
#define ClearPortFeature (0x2300 | USB_REQ_CLEAR_FEATURE)
#define GetHubDescriptor (0xA000 | USB_REQ_GET_DESCRIPTOR)
#define GetHubStatus (0xA000 | USB_REQ_GET_STATUS)
#define GetPortStatus (0xA300 | USB_REQ_GET_STATUS)
#define SetHubFeature (0x2000 | USB_REQ_SET_FEATURE)
#define SetPortFeature (0x2300 | USB_REQ_SET_FEATURE)
#define SetPortFeature (0x2300 | USB_REQ_SET_FEATURE)
#define PORT_CONNECTION 0
#define PORT_ENABLE 1
#define PORT_SUSPEND 2
@ -84,90 +84,90 @@ namespace xboxkrnl
#define PORT_C_ENABLE 17
#define PORT_C_SUSPEND 18
#define PORT_C_OVERCURRENT 19
#define PORT_C_RESET 20
// Acknowledgment: XQEMU (GPLv2)
// https://xqemu.com/
// To avoid including Xbox.h
extern USBDevice* g_USB0;
Hub* g_HubObjArray[4] = { nullptr };
#define PORT_C_RESET 20
// Acknowledgment: XQEMU (GPLv2)
// https://xqemu.com/
// To avoid including Xbox.h
extern USBDevice* g_USB0;
Hub* g_HubObjArray[4] = { nullptr };
struct USBHubPort {
USBPort port; // downstream port status
uint16_t wPortStatus; // Port Status Field, in accordance with the standard
uint16_t wPortChange; // Port Change Field, in accordance with the standard
};
};
struct USBHubState {
XboxDeviceState dev; // hub device status
USBEndpoint* intr; // interrupt endpoint of the hub
USBHubPort ports[NUM_PORTS]; // downstream ports of the hub
};
};
static const USBDescEndpoint desc_endp_hub = {
USB_DIR_IN | 0x01, // bEndpointAddress;
USB_ENDPOINT_XFER_INT, // bmAttributes;
1 + (NUM_PORTS + 7) / 8, // wMaxPacketSize;
0xFF, // bInterval;
0, // bRefresh;
0, // bSynchAddress
0, // is_audio
USB_DIR_IN | 0x01, // bEndpointAddress;
USB_ENDPOINT_XFER_INT, // bmAttributes;
1 + (NUM_PORTS + 7) / 8, // wMaxPacketSize;
0xFF, // bInterval;
0, // bRefresh;
0, // bSynchAddress
0, // is_audio
nullptr // extra
};
static const USBDescIface desc_iface_hub = {
0, // bInterfaceNumber;
0, // bAlternateSetting;
1, // bNumEndpoints;
USB_CLASS_HUB, // bInterfaceClass;
0, // bInterfaceSubClass
0, // bInterfaceProtocol
0, // iInterface
0, // ndesc
nullptr, // descs
0, // bInterfaceNumber;
0, // bAlternateSetting;
1, // bNumEndpoints;
USB_CLASS_HUB, // bInterfaceClass;
0, // bInterfaceSubClass
0, // bInterfaceProtocol
0, // iInterface
0, // ndesc
nullptr, // descs
&desc_endp_hub
};
static const USBDescConfig desc_config_hub = {
1, // bNumInterfaces
1, // bConfigurationValue
0, // iConfiguration
0xE0, // bmAttributes
0, // bMaxPower
1, // nif
&desc_iface_hub
};
static const USBDescDevice desc_device_hub = {
0x0110, // bcdUSB
USB_CLASS_HUB, // bDeviceClass
0, // bDeviceSubClass
0, // bDeviceProtocol
8, // bMaxPacketSize0
1, // bNumConfigurations
&desc_config_hub
static const USBDescConfig desc_config_hub = {
1, // bNumInterfaces
1, // bConfigurationValue
0, // iConfiguration
0xE0, // bmAttributes
0, // bMaxPower
1, // nif
&desc_iface_hub
};
static const USBDesc desc_hub = {
{
0x0409, // idVendor
0x55AA, // idProduct
0x0101, // bcdDevice
STR_MANUFACTURER, // iManufacturer
STR_PRODUCT, // iProduct
STR_SERIALNUMBER // iSerialNumber
},
&desc_device_hub
};
// Class-specific hub descriptor. Remember to update DeviceRemovable and PortPwrCtrlMask if you change NUM_PORTS since their values depend on
// the number of downstream ports available on the hub! Also note that this descriptor cannot be put in the descs member of the interface descriptor
// because then this descriptor will be retrieved during a standard GetDescriptor request instead of the hub-specific GetHubDescriptor request
static const USBDescDevice desc_device_hub = {
0x0110, // bcdUSB
USB_CLASS_HUB, // bDeviceClass
0, // bDeviceSubClass
0, // bDeviceProtocol
8, // bMaxPacketSize0
1, // bNumConfigurations
&desc_config_hub
};
static const USBDesc desc_hub = {
{
0x0409, // idVendor
0x55AA, // idProduct
0x0101, // bcdDevice
STR_MANUFACTURER, // iManufacturer
STR_PRODUCT, // iProduct
STR_SERIALNUMBER // iSerialNumber
},
&desc_device_hub
};
// Class-specific hub descriptor. Remember to update DeviceRemovable and PortPwrCtrlMask if you change NUM_PORTS since their values depend on
// the number of downstream ports available on the hub! Also note that this descriptor cannot be put in the descs member of the interface descriptor
// because then this descriptor will be retrieved during a standard GetDescriptor request instead of the hub-specific GetHubDescriptor request
static const uint8_t HubDescriptor[] =
{
0x0A, // u8 bDescLength; 10 bytes
@ -180,128 +180,128 @@ static const uint8_t HubDescriptor[] =
0x00, // u16 DeviceRemovable; all devices are removable
0x00,
0xFF, // u8 PortPwrCtrlMask; all 1's for compatibility reasons
};
int Hub::Init(int port)
{
if (port > 4 || port < 1) { return -1; };
XboxDeviceState* dev = ClassInitFn();
int rc = UsbHubClaimPort(dev, port);
if (rc != 0) {
m_UsbDev->m_HostController->m_bFrameTime = false;
return rc;
}
m_UsbDev->USB_EpInit(dev);
m_UsbDev->USB_DeviceInit(dev);
m_UsbDev->USB_DeviceAttach(dev);
m_UsbDev->m_HostController->m_bFrameTime = false;
return 0;
}
XboxDeviceState* Hub::ClassInitFn()
{
m_pPeripheralFuncStruct = new USBDeviceClass();
m_HubState = new USBHubState();
XboxDeviceState* dev = &m_HubState->dev;
dev->ProductDesc = "Cxbx-Reloaded USB Hub";
QLIST_INIT(&dev->Strings);
dev->klass = m_pPeripheralFuncStruct;
{
using namespace std::placeholders;
m_pPeripheralFuncStruct->init = std::bind(&Hub::UsbHub_Initfn, this, _1);
m_pPeripheralFuncStruct->find_device = std::bind(&Hub::UsbHub_FindDevice, this, _1, _2);
m_pPeripheralFuncStruct->handle_reset = std::bind(&Hub::UsbHub_HandleReset, this);
m_pPeripheralFuncStruct->handle_control = std::bind(&Hub::UsbHub_HandleControl, this, _1, _2, _3, _4, _5, _6, _7);
m_pPeripheralFuncStruct->handle_data = std::bind(&Hub::UsbHub_HandleData, this, _1, _2);
m_pPeripheralFuncStruct->handle_destroy = std::bind(&Hub::UsbHub_HandleDestroy, this);
m_pPeripheralFuncStruct->product_desc = dev->ProductDesc.c_str();
m_pPeripheralFuncStruct->usb_desc = &desc_hub;
}
return dev;
}
int Hub::UsbHubClaimPort(XboxDeviceState* dev, int port)
{
int i;
std::vector<USBPort*>::iterator it;
assert(dev->Port == nullptr);
m_UsbDev = g_USB0;
it = m_UsbDev->m_FreePorts.end();
i = 0;
while (m_UsbDev->m_HostController->m_bFrameTime) { Sleep(1); }
m_UsbDev->m_HostController->m_bFrameTime = true;
for (auto usb_port : m_UsbDev->m_FreePorts) {
if (usb_port->Path == std::to_string(port)) {
it = m_UsbDev->m_FreePorts.begin() + i;
break;
}
i++;
}
if (it == m_UsbDev->m_FreePorts.end()) {
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Port requested %d not found (in use?)", port);
return -1;
}
dev->Port = *it;
(*it)->Dev = dev;
m_UsbDev->m_FreePorts.erase(it);
return 0;
}
void Hub::UsbHubReleasePort(XboxDeviceState* dev)
{
USBPort* port = dev->Port;
assert(port != nullptr);
port->Dev = nullptr;
dev->Port = nullptr;
}
int Hub::UsbHub_Initfn(XboxDeviceState* dev)
{
USBHubPort* port;
USBPortOps* ops;
int i;
m_UsbDev->USB_CreateSerial(dev, std::string("314159"));
m_UsbDev->USBDesc_SetString(dev, STR_MANUFACTURER, std::string("Cxbx-Reloaded"));
m_UsbDev->USBDesc_SetString(dev, STR_PRODUCT, std::string("Cxbx-Reloaded USB Hub"));
m_UsbDev->USBDesc_Init(dev);
m_HubState->intr = m_UsbDev->USB_GetEP(dev, USB_TOKEN_IN, 1);
ops = new USBPortOps();
{
using namespace std::placeholders;
ops->attach = std::bind(&Hub::UsbHub_Attach, this, _1);
ops->detach = std::bind(&Hub::UsbHub_Detach, this, _1);
ops->child_detach = std::bind(&Hub::UsbHub_ChildDetach, this, _1);
ops->wakeup = std::bind(&Hub::UsbHub_Wakeup, this, _1);
ops->complete = std::bind(&Hub::UsbHub_Complete, this, _1, _2);
}
for (i = 0; i < NUM_PORTS; i++) {
port = &m_HubState->ports[i];
m_UsbDev->USB_RegisterPort(&port->port, i, USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL, ops);
m_UsbDev->USB_PortLocation(&port->port, dev->Port, i + 1);
}
UsbHub_HandleReset();
return 0;
}
XboxDeviceState* Hub::UsbHub_FindDevice(XboxDeviceState* dev, uint8_t addr)
};
int Hub::Init(int port)
{
if (port > 4 || port < 1) { return -1; };
XboxDeviceState* dev = ClassInitFn();
int rc = UsbHubClaimPort(dev, port);
if (rc != 0) {
m_UsbDev->m_HostController->m_bFrameTime = false;
return rc;
}
m_UsbDev->USB_EpInit(dev);
m_UsbDev->USB_DeviceInit(dev);
m_UsbDev->USB_DeviceAttach(dev);
m_UsbDev->m_HostController->m_bFrameTime = false;
return 0;
}
XboxDeviceState* Hub::ClassInitFn()
{
m_pPeripheralFuncStruct = new USBDeviceClass();
m_HubState = new USBHubState();
XboxDeviceState* dev = &m_HubState->dev;
dev->ProductDesc = "Cxbx-Reloaded USB Hub";
QLIST_INIT(&dev->Strings);
dev->klass = m_pPeripheralFuncStruct;
{
using namespace std::placeholders;
m_pPeripheralFuncStruct->init = std::bind(&Hub::UsbHub_Initfn, this, _1);
m_pPeripheralFuncStruct->find_device = std::bind(&Hub::UsbHub_FindDevice, this, _1, _2);
m_pPeripheralFuncStruct->handle_reset = std::bind(&Hub::UsbHub_HandleReset, this);
m_pPeripheralFuncStruct->handle_control = std::bind(&Hub::UsbHub_HandleControl, this, _1, _2, _3, _4, _5, _6, _7);
m_pPeripheralFuncStruct->handle_data = std::bind(&Hub::UsbHub_HandleData, this, _1, _2);
m_pPeripheralFuncStruct->handle_destroy = std::bind(&Hub::UsbHub_HandleDestroy, this);
m_pPeripheralFuncStruct->product_desc = dev->ProductDesc.c_str();
m_pPeripheralFuncStruct->usb_desc = &desc_hub;
}
return dev;
}
int Hub::UsbHubClaimPort(XboxDeviceState* dev, int port)
{
int i;
std::vector<USBPort*>::iterator it;
assert(dev->Port == nullptr);
m_UsbDev = g_USB0;
it = m_UsbDev->m_FreePorts.end();
i = 0;
while (m_UsbDev->m_HostController->m_bFrameTime) { Sleep(1); }
m_UsbDev->m_HostController->m_bFrameTime = true;
for (auto usb_port : m_UsbDev->m_FreePorts) {
if (usb_port->Path == std::to_string(port)) {
it = m_UsbDev->m_FreePorts.begin() + i;
break;
}
i++;
}
if (it == m_UsbDev->m_FreePorts.end()) {
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Port requested %d not found (in use?)", port);
return -1;
}
dev->Port = *it;
(*it)->Dev = dev;
m_UsbDev->m_FreePorts.erase(it);
return 0;
}
void Hub::UsbHubReleasePort(XboxDeviceState* dev)
{
USBPort* port = dev->Port;
assert(port != nullptr);
port->Dev = nullptr;
dev->Port = nullptr;
}
int Hub::UsbHub_Initfn(XboxDeviceState* dev)
{
USBHubPort* port;
USBPortOps* ops;
int i;
m_UsbDev->USB_CreateSerial(dev, std::string("314159"));
m_UsbDev->USBDesc_SetString(dev, STR_MANUFACTURER, std::string("Cxbx-Reloaded"));
m_UsbDev->USBDesc_SetString(dev, STR_PRODUCT, std::string("Cxbx-Reloaded USB Hub"));
m_UsbDev->USBDesc_Init(dev);
m_HubState->intr = m_UsbDev->USB_GetEP(dev, USB_TOKEN_IN, 1);
ops = new USBPortOps();
{
using namespace std::placeholders;
ops->attach = std::bind(&Hub::UsbHub_Attach, this, _1);
ops->detach = std::bind(&Hub::UsbHub_Detach, this, _1);
ops->child_detach = std::bind(&Hub::UsbHub_ChildDetach, this, _1);
ops->wakeup = std::bind(&Hub::UsbHub_Wakeup, this, _1);
ops->complete = std::bind(&Hub::UsbHub_Complete, this, _1, _2);
}
for (i = 0; i < NUM_PORTS; i++) {
port = &m_HubState->ports[i];
m_UsbDev->USB_RegisterPort(&port->port, i, USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL, ops);
m_UsbDev->USB_PortLocation(&port->port, dev->Port, i + 1);
}
UsbHub_HandleReset();
return 0;
}
XboxDeviceState* Hub::UsbHub_FindDevice(XboxDeviceState* dev, uint8_t addr)
{
USBHubPort* port;
XboxDeviceState* downstream;
@ -316,10 +316,10 @@ XboxDeviceState* Hub::UsbHub_FindDevice(XboxDeviceState* dev, uint8_t addr)
return downstream;
}
}
return nullptr;
}
void Hub::UsbHub_HandleReset()
return nullptr;
}
void Hub::UsbHub_HandleReset()
{
USBHubPort* port;
@ -334,11 +334,11 @@ void Hub::UsbHub_HandleReset()
port->wPortStatus |= PORT_STAT_LOW_SPEED;
}
}
}
}
void Hub::UsbHub_HandleControl(XboxDeviceState* dev, USBPacket* p,
int request, int value, int index, int length, uint8_t* data)
}
}
void Hub::UsbHub_HandleControl(XboxDeviceState* dev, USBPacket* p,
int request, int value, int index, int length, uint8_t* data)
{
int ret;
@ -377,7 +377,7 @@ void Hub::UsbHub_HandleControl(XboxDeviceState* dev, USBPacket* p,
goto fail;
}
port = &m_HubState->ports[n];
DbgPrintf(LOG_PREFIX, "%s GetPortStatus -> Address 0x%X, wIndex %d, wPortStatus %d, wPortChange %d\n",
DBG_PRINTF("%s GetPortStatus -> Address 0x%X, wIndex %d, wPortStatus %d, wPortChange %d\n",
__func__, m_HubState->dev.Addr, index, port->wPortStatus, port->wPortChange);
data[0] = port->wPortStatus;
data[1] = port->wPortStatus >> 8;
@ -402,7 +402,7 @@ void Hub::UsbHub_HandleControl(XboxDeviceState* dev, USBPacket* p,
USBHubPort* port;
XboxDeviceState* dev;
DbgPrintf(LOG_PREFIX, "%s SetPortFeature -> Address 0x%X, wIndex %d, Feature %s\n",
DBG_PRINTF("%s SetPortFeature -> Address 0x%X, wIndex %d, Feature %s\n",
__func__, m_HubState->dev.Addr, index, GetFeatureName(value));
if (n >= NUM_PORTS) {
@ -440,7 +440,7 @@ void Hub::UsbHub_HandleControl(XboxDeviceState* dev, USBPacket* p,
unsigned int n = index - 1;
USBHubPort *port;
DbgPrintf(LOG_PREFIX, "%s ClearPortFeature -> Address 0x%X, wIndex %d, Feature %s\n",
DBG_PRINTF("%s ClearPortFeature -> Address 0x%X, wIndex %d, Feature %s\n",
__func__, m_HubState->dev.Addr, index, GetFeatureName(value));
if (n >= NUM_PORTS) {
@ -499,9 +499,9 @@ void Hub::UsbHub_HandleControl(XboxDeviceState* dev, USBPacket* p,
fail:
p->Status = USB_RET_STALL;
break;
}
}
}
}
void Hub::UsbHub_HandleData(XboxDeviceState* dev, USBPacket* p)
{
switch (p->Pid) {
@ -527,7 +527,7 @@ void Hub::UsbHub_HandleData(XboxDeviceState* dev, USBPacket* p)
p->Status = USB_RET_BABBLE;
return;
}
DbgPrintf(LOG_PREFIX, "%s Address 0x%X, Status %d\n", __func__, m_HubState->dev.Addr, status);
DBG_PRINTF("%s Address 0x%X, Status %d\n", __func__, m_HubState->dev.Addr, status);
for (i = 0; i < n; i++) {
buf[i] = status >> (8 * i);
}
@ -549,8 +549,8 @@ void Hub::UsbHub_HandleData(XboxDeviceState* dev, USBPacket* p)
p->Status = USB_RET_STALL;
break;
}
}
}
void Hub::UsbHub_HandleDestroy()
{
// Inform upstream that the hub is detached and gone
@ -568,24 +568,24 @@ void Hub::UsbHub_HandleDestroy()
}
UsbHubReleasePort(&m_HubState->dev);
HubCleanUp();
}
void Hub::UsbHub_Attach(USBPort* port1)
{
USBHubPort* port = &m_HubState->ports[port1->PortIndex];
port->wPortStatus |= PORT_STAT_CONNECTION;
port->wPortChange |= PORT_STAT_C_CONNECTION;
if (port->port.Dev->Speed == USB_SPEED_LOW) {
port->wPortStatus |= PORT_STAT_LOW_SPEED;
}
else {
port->wPortStatus &= ~PORT_STAT_LOW_SPEED;
}
m_UsbDev->USB_Wakeup(m_HubState->intr);
}
void Hub::UsbHub_Detach(USBPort* port1)
}
void Hub::UsbHub_Attach(USBPort* port1)
{
USBHubPort* port = &m_HubState->ports[port1->PortIndex];
port->wPortStatus |= PORT_STAT_CONNECTION;
port->wPortChange |= PORT_STAT_C_CONNECTION;
if (port->port.Dev->Speed == USB_SPEED_LOW) {
port->wPortStatus |= PORT_STAT_LOW_SPEED;
}
else {
port->wPortStatus &= ~PORT_STAT_LOW_SPEED;
}
m_UsbDev->USB_Wakeup(m_HubState->intr);
}
void Hub::UsbHub_Detach(USBPort* port1)
{
USBHubPort* port = &m_HubState->ports[port1->PortIndex];
@ -600,31 +600,31 @@ void Hub::UsbHub_Detach(USBPort* port1)
port->wPortStatus &= ~PORT_STAT_ENABLE;
port->wPortChange |= PORT_STAT_C_ENABLE;
}
m_UsbDev->USB_Wakeup(m_HubState->intr);
}
void Hub::UsbHub_ChildDetach(XboxDeviceState* child)
m_UsbDev->USB_Wakeup(m_HubState->intr);
}
void Hub::UsbHub_ChildDetach(XboxDeviceState* child)
{
// Pass along to upstream
m_HubState->dev.Port->Operations->child_detach(child);
}
void Hub::UsbHub_Wakeup(USBPort* port1)
m_HubState->dev.Port->Operations->child_detach(child);
}
void Hub::UsbHub_Wakeup(USBPort* port1)
{
USBHubPort* port = &m_HubState->ports[port1->PortIndex];
if (port->wPortStatus & PORT_STAT_SUSPEND) {
port->wPortChange |= PORT_STAT_C_SUSPEND;
m_UsbDev->USB_Wakeup(m_HubState->intr);
}
}
void Hub::UsbHub_Complete(USBPort* port, USBPacket* packet)
{
// Just pass it along to upstream
m_HubState->dev.Port->Operations->complete(m_HubState->dev.Port, packet);
}
}
}
void Hub::UsbHub_Complete(USBPort* port, USBPacket* packet)
{
// Just pass it along to upstream
m_HubState->dev.Port->Operations->complete(m_HubState->dev.Port, packet);
}
std::string Hub::GetFeatureName(int feature)
{
std::string str;
@ -699,18 +699,18 @@ std::string Hub::GetFeatureName(int feature)
}
void Hub::HubCleanUp()
{
delete m_pPeripheralFuncStruct;
delete m_HubState->ports[0].port.Operations;
delete m_HubState;
m_pPeripheralFuncStruct = nullptr;
{
delete m_pPeripheralFuncStruct;
delete m_HubState->ports[0].port.Operations;
delete m_HubState;
m_pPeripheralFuncStruct = nullptr;
m_HubState = nullptr;
}
void Hub::HubDestroy()
{
while (m_UsbDev->m_HostController->m_bFrameTime) { Sleep(1); }
m_UsbDev->m_HostController->m_bFrameTime = true;
m_pPeripheralFuncStruct->handle_destroy();
m_UsbDev->m_HostController->m_bFrameTime = false;
}
void Hub::HubDestroy()
{
while (m_UsbDev->m_HostController->m_bFrameTime) { Sleep(1); }
m_UsbDev->m_HostController->m_bFrameTime = true;
m_pPeripheralFuncStruct->handle_destroy();
m_UsbDev->m_HostController->m_bFrameTime = false;
}

View File

@ -33,23 +33,23 @@
// * All rights reserved
// *
// ******************************************************************
#define _XBOXKRNL_DEFEXTRN_
#define LOG_PREFIX CXBXR_MODULE::OHCI
/* prevent name collisions */
namespace xboxkrnl
{
#include <xboxkrnl/xboxkrnl.h>
};
#define LOG_PREFIX CXBXR_MODULE::OHCI
/* prevent name collisions */
namespace xboxkrnl
{
#include <xboxkrnl/xboxkrnl.h>
};
#include "OHCI.h"
#include "CxbxKrnl\EmuKrnl.h" // For HalSystemInterrupt
#include "CxbxCommon.h"
#include "Logging.h"
/* Define these two if you want to dump usb packets */
#include "CxbxKrnl\EmuKrnl.h" // For HalSystemInterrupt
#include "CxbxCommon.h"
#include "Logging.h"
/* Define these two if you want to dump usb packets */
//#define DEBUG_ISOCH
//#define DEBUG_PACKET
@ -200,10 +200,10 @@ namespace xboxkrnl
#define OHCI_PAGE_MASK 0xFFFFF000
#define OHCI_OFFSET_MASK 0xFFF
// Acknowledgment: XQEMU (GPLv2)
// https://xqemu.com/
// Acknowledgment: XQEMU (GPLv2)
// https://xqemu.com/
OHCI::OHCI(USBDevice* UsbObj)
@ -211,17 +211,17 @@ OHCI::OHCI(USBDevice* UsbObj)
int offset = 0;
USBPortOps* ops;
m_UsbDevice = UsbObj;
m_UsbDevice = UsbObj;
m_bFrameTime = false;
ops = new USBPortOps();
{
using namespace std::placeholders;
ops->attach = std::bind(&OHCI::OHCI_Attach, this, _1);
ops->detach = std::bind(&OHCI::OHCI_Detach, this, _1);
ops->child_detach = std::bind(&OHCI::OHCI_ChildDetach, this, _1);
ops->wakeup = std::bind(&OHCI::OHCI_Wakeup, this, _1);
ops->complete = std::bind(&OHCI::OHCI_AsyncCompletePacket, this, _1, _2);
{
using namespace std::placeholders;
ops->attach = std::bind(&OHCI::OHCI_Attach, this, _1);
ops->detach = std::bind(&OHCI::OHCI_Detach, this, _1);
ops->child_detach = std::bind(&OHCI::OHCI_ChildDetach, this, _1);
ops->wakeup = std::bind(&OHCI::OHCI_Wakeup, this, _1);
ops->complete = std::bind(&OHCI::OHCI_AsyncCompletePacket, this, _1, _2);
}
for (int i = 0; i < 4; i++) {
@ -243,14 +243,14 @@ void OHCI::OHCI_FrameBoundaryWrapper(void* pVoid)
void OHCI::OHCI_FrameBoundaryWorker()
{
OHCI_HCCA hcca;
while (m_bFrameTime) { Sleep(1); }
OHCI_HCCA hcca;
while (m_bFrameTime) { Sleep(1); }
m_bFrameTime = true;
if (OHCI_ReadHCCA(m_Registers.HcHCCA, &hcca)) {
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "HCCA read error at physical address 0x%X", m_Registers.HcHCCA);
OHCI_FatalError();
OHCI_FatalError();
m_bFrameTime = false;
return;
}
@ -275,14 +275,14 @@ void OHCI::OHCI_FrameBoundaryWorker()
OHCI_ProcessLists(0);
// Stop if UnrecoverableError happened or OHCI_SOF will crash
if (m_Registers.HcInterruptStatus & OHCI_INTR_UE) {
if (m_Registers.HcInterruptStatus & OHCI_INTR_UE) {
m_bFrameTime = false;
return;
}
// From the standard: "This bit is loaded from the FrameIntervalToggle field of
// HcFmInterval whenever FrameRemaining reaches 0."
m_Registers.HcFmRemaining = (m_Registers.HcFmInterval & OHCI_FMI_FIT) == 0 ?
m_Registers.HcFmRemaining = (m_Registers.HcFmInterval & OHCI_FMI_FIT) == 0 ?
m_Registers.HcFmRemaining & ~OHCI_FMR_FRT : m_Registers.HcFmRemaining | OHCI_FMR_FRT;
// Increment frame number
@ -322,8 +322,8 @@ void OHCI::OHCI_FrameBoundaryWorker()
if (OHCI_WriteHCCA(m_Registers.HcHCCA, &hcca)) {
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "HCCA write error at physical address 0x%X", m_Registers.HcHCCA);
OHCI_FatalError();
}
}
m_bFrameTime = false;
}
@ -339,7 +339,7 @@ void OHCI::OHCI_FatalError()
}
bool OHCI::OHCI_ReadHCCA(xbaddr Paddr, OHCI_HCCA* Hcca)
{
{
// ergo720: what's written below is true if we identity map only allocations served by VirtualAlloc.
// There could be a peculiar problem if the shared memory between HCD and HC is allocated by the
// VMManager with VirtualAlloc: the physical allocation would not reside in memory.bin and if we tried to
@ -594,7 +594,7 @@ int OHCI::OHCI_ServiceTD(OHCI_ED* Ed)
// See if this TD has already been submitted to the device
completion = (addr == m_AsyncTD);
if (completion && !m_AsyncComplete) {
DbgPrintf(LOG_PREFIX, "Skipping async TD\n");
DBG_PRINTF("Skipping async TD\n");
return 1;
}
if (OHCI_ReadTD(addr, &td)) {
@ -698,7 +698,7 @@ int OHCI::OHCI_ServiceTD(OHCI_ED* Ed)
// From XQEMU: "??? The hardware should allow one active packet per endpoint.
// We only allow one active packet per controller. This should be sufficient
// as long as devices respond in a timely manner."
DbgPrintf(LOG_PREFIX, "too many pending packets\n");
DBG_PRINTF("too many pending packets\n");
return 1;
}
dev = OHCI_FindDevice(OHCI_BM(Ed->Flags, ED_FA));
@ -772,29 +772,29 @@ int OHCI::OHCI_ServiceTD(OHCI_ED* Ed)
}
else {
if (ret >= 0) {
DbgPrintf(LOG_PREFIX, "Underrun\n");
DBG_PRINTF("Underrun\n");
OHCI_SET_BM(td.Flags, TD_CC, OHCI_CC_DATAUNDERRUN);
}
else {
switch (ret) {
case USB_RET_IOERROR:
case USB_RET_NODEV:
DbgPrintf(LOG_PREFIX, "Received DEV ERROR\n");
DBG_PRINTF("Received DEV ERROR\n");
OHCI_SET_BM(td.Flags, TD_CC, OHCI_CC_DEVICENOTRESPONDING);
break;
case USB_RET_NAK:
DbgPrintf(LOG_PREFIX, "Received NAK\n");
DBG_PRINTF("Received NAK\n");
return 1;
case USB_RET_STALL:
DbgPrintf(LOG_PREFIX, "Received STALL\n");
DBG_PRINTF("Received STALL\n");
OHCI_SET_BM(td.Flags, TD_CC, OHCI_CC_STALL);
break;
case USB_RET_BABBLE:
DbgPrintf(LOG_PREFIX, "Received BABBLE\n");
DBG_PRINTF("Received BABBLE\n");
OHCI_SET_BM(td.Flags, TD_CC, OHCI_CC_DATAOVERRUN);
break;
default:
DbgPrintf(LOG_PREFIX, "Bad device response %d\n", ret);
DBG_PRINTF("Bad device response %d\n", ret);
OHCI_SET_BM(td.Flags, TD_CC, OHCI_CC_UNDEXPETEDPID);
OHCI_SET_BM(td.Flags, TD_EC, 3);
}
@ -891,7 +891,7 @@ void OHCI::OHCI_StateReset()
OHCI_StopEndpoints();
DbgPrintf(LOG_PREFIX, "Reset mode event.\n");
DBG_PRINTF("Reset mode event.\n");
}
void OHCI::OHCI_BusStart()
@ -899,7 +899,7 @@ void OHCI::OHCI_BusStart()
// Create the EOF timer. Let's try a factor of 50 (1 virtual ms -> 50 real ms)
m_pEOFtimer = Timer_Create(OHCI_FrameBoundaryWrapper, this, 50);
DbgPrintf(LOG_PREFIX, "Operational mode event\n");
DBG_PRINTF("Operational mode event\n");
// SOF event
OHCI_SOF(true);
@ -946,11 +946,11 @@ void OHCI::OHCI_ChangeState(uint32_t Value)
case Suspend:
OHCI_BusStop();
DbgPrintf(LOG_PREFIX, "Suspend mode event\n");
DBG_PRINTF("Suspend mode event\n");
break;
case Resume:
DbgPrintf(LOG_PREFIX, "Resume mode event\n");
DBG_PRINTF("Resume mode event\n");
break;
case Reset:
@ -977,7 +977,7 @@ uint32_t OHCI::OHCI_ReadRegister(xbaddr Addr)
if (Addr & 3) {
// The standard allows only aligned reads to the registers
DbgPrintf(LOG_PREFIX, "Unaligned read. Ignoring.\n");
DBG_PRINTF("Unaligned read. Ignoring.\n");
return ret;
}
else {
@ -1071,14 +1071,14 @@ uint32_t OHCI::OHCI_ReadRegister(xbaddr Addr)
case 22: // RhPort 1
ret = m_Registers.RhPort[1].HcRhPortStatus | OHCI_PORT_PPS;
break;
case 23:
ret = m_Registers.RhPort[2].HcRhPortStatus | OHCI_PORT_PPS;
break;
case 24:
ret = m_Registers.RhPort[3].HcRhPortStatus | OHCI_PORT_PPS;
break;
case 23:
ret = m_Registers.RhPort[2].HcRhPortStatus | OHCI_PORT_PPS;
break;
case 24:
ret = m_Registers.RhPort[3].HcRhPortStatus | OHCI_PORT_PPS;
break;
default:
@ -1092,7 +1092,7 @@ void OHCI::OHCI_WriteRegister(xbaddr Addr, uint32_t Value)
{
if (Addr & 3) {
// The standard allows only aligned writes to the registers
DbgPrintf(LOG_PREFIX, "Unaligned write. Ignoring.\n");
DBG_PRINTF("Unaligned write. Ignoring.\n");
return;
}
else {
@ -1169,7 +1169,7 @@ void OHCI::OHCI_WriteRegister(xbaddr Addr, uint32_t Value)
case 13: // HcFmInterval
{
if ((Value & OHCI_FMI_FI) != (m_Registers.HcFmInterval & OHCI_FMI_FI)) {
DbgPrintf(LOG_PREFIX, "Changing frame interval duration. New value is %u\n", Value & OHCI_FMI_FI);
DBG_PRINTF("Changing frame interval duration. New value is %u\n", Value & OHCI_FMI_FI);
}
m_Registers.HcFmInterval = Value & ~0xC000;
}
@ -1210,14 +1210,14 @@ void OHCI::OHCI_WriteRegister(xbaddr Addr, uint32_t Value)
case 22: // RhPort 1
OHCI_PortSetStatus(1, Value);
break;
break;
case 23: // RhPort 2
OHCI_PortSetStatus(2, Value);
break;
OHCI_PortSetStatus(2, Value);
break;
case 24: // RhPort 3
OHCI_PortSetStatus(3, Value);
OHCI_PortSetStatus(3, Value);
break;
default:
@ -1228,7 +1228,7 @@ void OHCI::OHCI_WriteRegister(xbaddr Addr, uint32_t Value)
void OHCI::OHCI_UpdateInterrupt()
{
if ((m_Registers.HcInterrupt & OHCI_INTR_MIE) && (m_Registers.HcInterruptStatus & m_Registers.HcInterrupt)) {
if ((m_Registers.HcInterrupt & OHCI_INTR_MIE) && (m_Registers.HcInterruptStatus & m_Registers.HcInterrupt)) {
HalSystemInterrupts[1].Assert(false);
HalSystemInterrupts[1].Assert(true);
}
@ -1297,7 +1297,7 @@ void OHCI::OHCI_SetHubStatus(uint32_t Value)
for (i = 0; i < 4; i++) {
OHCI_PortPower(i, 0);
}
DbgPrintf(LOG_PREFIX, "powered down all ports\n");
DBG_PRINTF("powered down all ports\n");
}
if (Value & OHCI_RHS_LPSC) {
@ -1306,7 +1306,7 @@ void OHCI::OHCI_SetHubStatus(uint32_t Value)
for (i = 0; i < 4; i++) {
OHCI_PortPower(i, 1);
}
DbgPrintf(LOG_PREFIX, "powered up all ports\n");
DBG_PRINTF("powered up all ports\n");
}
if (Value & OHCI_RHS_DRWE) {
@ -1355,11 +1355,11 @@ void OHCI::OHCI_PortSetStatus(int PortNum, uint32_t Value)
OHCI_PortSetIfConnected(PortNum, Value & OHCI_PORT_PES);
if (OHCI_PortSetIfConnected(PortNum, Value & OHCI_PORT_PSS)) {
DbgPrintf(LOG_PREFIX, "port %d: SUSPEND\n", PortNum);
DBG_PRINTF("port %d: SUSPEND\n", PortNum);
}
if (OHCI_PortSetIfConnected(PortNum, Value & OHCI_PORT_PRS)) {
DbgPrintf(LOG_PREFIX, "port %d: RESET\n", PortNum);
DBG_PRINTF("port %d: RESET\n", PortNum);
m_UsbDevice->USB_DeviceReset(port->UsbPort.Dev);
port->HcRhPortStatus &= ~OHCI_PORT_PRS;
// ??? Should this also set OHCI_PORT_PESC
@ -1427,7 +1427,7 @@ void OHCI::OHCI_Detach(USBPort* Port)
port->HcRhPortStatus |= OHCI_PORT_PESC;
}
DbgPrintf(LOG_PREFIX, "Detached port %d\n", Port->PortIndex);
DBG_PRINTF("Detached port %d\n", Port->PortIndex);
if (old_state != port->HcRhPortStatus) {
OHCI_SetInterrupt(OHCI_INTR_RHSC);
@ -1455,7 +1455,7 @@ void OHCI::OHCI_Attach(USBPort* Port)
OHCI_SetInterrupt(OHCI_INTR_RD);
}
DbgPrintf(LOG_PREFIX, "Attached port %d\n", Port->PortIndex);
DBG_PRINTF("Attached port %d\n", Port->PortIndex);
if (old_state != port->HcRhPortStatus) {
OHCI_SetInterrupt(OHCI_INTR_RHSC);
@ -1467,36 +1467,36 @@ void OHCI::OHCI_ChildDetach(XboxDeviceState* child)
OHCI_AsyncCancelDevice(child);
}
void OHCI::OHCI_Wakeup(USBPort* port1)
{
OHCIPort* port = &m_Registers.RhPort[port1->PortIndex];
uint32_t intr = 0;
if (port->HcRhPortStatus & OHCI_PORT_PSS) {
DbgPrintf(LOG_PREFIX, "port %d: wakeup\n", port1->PortIndex);
port->HcRhPortStatus |= OHCI_PORT_PSSC;
port->HcRhPortStatus &= ~OHCI_PORT_PSS;
intr = OHCI_INTR_RHSC;
}
// Note that the controller can be suspended even if this port is not
if ((m_Registers.HcControl & OHCI_CTL_HCFS) == Suspend) {
DbgPrintf(LOG_PREFIX, "remote-wakeup: SUSPEND->RESUME\n");
// From the standard: "The only interrupts possible in the USBSUSPEND state are ResumeDetected (the
// Host Controller will have changed the HostControllerFunctionalState to the USBRESUME state)
// and OwnershipChange."
m_Registers.HcControl &= ~OHCI_CTL_HCFS;
m_Registers.HcControl |= Resume;
intr = OHCI_INTR_RD;
}
OHCI_SetInterrupt(intr);
void OHCI::OHCI_Wakeup(USBPort* port1)
{
OHCIPort* port = &m_Registers.RhPort[port1->PortIndex];
uint32_t intr = 0;
if (port->HcRhPortStatus & OHCI_PORT_PSS) {
DBG_PRINTF("port %d: wakeup\n", port1->PortIndex);
port->HcRhPortStatus |= OHCI_PORT_PSSC;
port->HcRhPortStatus &= ~OHCI_PORT_PSS;
intr = OHCI_INTR_RHSC;
}
// Note that the controller can be suspended even if this port is not
if ((m_Registers.HcControl & OHCI_CTL_HCFS) == Suspend) {
DBG_PRINTF("remote-wakeup: SUSPEND->RESUME\n");
// From the standard: "The only interrupts possible in the USBSUSPEND state are ResumeDetected (the
// Host Controller will have changed the HostControllerFunctionalState to the USBRESUME state)
// and OwnershipChange."
m_Registers.HcControl &= ~OHCI_CTL_HCFS;
m_Registers.HcControl |= Resume;
intr = OHCI_INTR_RD;
}
OHCI_SetInterrupt(intr);
}
void OHCI::OHCI_AsyncCompletePacket(USBPort* port, USBPacket* packet)
{
#ifdef DEBUG_PACKET
printf("Async packet complete\n");
#endif
m_AsyncComplete = 1;
OHCI_ProcessLists(1);
void OHCI::OHCI_AsyncCompletePacket(USBPort* port, USBPacket* packet)
{
#ifdef DEBUG_PACKET
printf("Async packet complete\n");
#endif
m_AsyncComplete = 1;
OHCI_ProcessLists(1);
}
void OHCI::OHCI_AsyncCancelDevice(XboxDeviceState* dev)
@ -1514,7 +1514,7 @@ void OHCI::OHCI_ProcessLists(int completion)
// Only process the control list if it is enabled (HcControl) and has available TD's (HcCommandStatus)
if ((m_Registers.HcControl & OHCI_CTL_CLE) && (m_Registers.HcCommandStatus & OHCI_STATUS_CLF)) {
if (m_Registers.HcControlCurrentED && m_Registers.HcControlCurrentED != m_Registers.HcControlHeadED) {
DbgPrintf(LOG_PREFIX, "head 0x%X, current 0x%X\n", m_Registers.HcControlHeadED, m_Registers.HcControlCurrentED);
DBG_PRINTF("head 0x%X, current 0x%X\n", m_Registers.HcControlHeadED, m_Registers.HcControlCurrentED);
}
if (!OHCI_ServiceEDlist(m_Registers.HcControlHeadED, completion)) {
m_Registers.HcControlCurrentED = 0;
@ -1554,7 +1554,7 @@ int OHCI::OHCI_ServiceIsoTD(OHCI_ED* ed, int completion)
addr = ed->HeadP & OHCI_DPTR_MASK;
if (OHCI_ReadIsoTD(addr, &iso_td)) {
DbgPrintf(LOG_PREFIX, "ISO_TD read error at physical address 0x%X\n", addr);
DBG_PRINTF("ISO_TD read error at physical address 0x%X\n", addr);
OHCI_FatalError();
return 0;
}
@ -1585,13 +1585,13 @@ int OHCI::OHCI_ServiceIsoTD(OHCI_ED* ed, int completion)
if (relative_frame_number < 0) {
// From the standard: "If the relative frame number is negative, then the current frame is earlier than the 0th frame
// of the Isochronous TD and the Host Controller advances to the next ED."
DbgPrintf(LOG_PREFIX, "ISO_TD R=%d < 0\n", relative_frame_number);
DBG_PRINTF("ISO_TD R=%d < 0\n", relative_frame_number);
return 1;
}
else if (relative_frame_number > frame_count) {
// From the standard: "If the relative frame number is greater than
// FrameCount, then the Isochronous TD has expired and a error condition exists."
DbgPrintf(LOG_PREFIX, "ISO_TD R=%d > FC=%d\n", relative_frame_number, frame_count);
DBG_PRINTF("ISO_TD R=%d > FC=%d\n", relative_frame_number, frame_count);
OHCI_SET_BM(iso_td.Flags, TD_CC, OHCI_CC_DATAOVERRUN);
ed->HeadP &= ~OHCI_DPTR_MASK;
ed->HeadP |= (iso_td.NextTD & OHCI_DPTR_MASK);
@ -1637,7 +1637,7 @@ int OHCI::OHCI_ServiceIsoTD(OHCI_ED* ed, int completion)
}
if (!iso_td.BufferPage0 || !iso_td.BufferEnd) {
DbgPrintf(LOG_PREFIX, "ISO_TD bp 0x%.8X be 0x%.8X\n", iso_td.BufferPage0, iso_td.BufferEnd);
DBG_PRINTF("ISO_TD bp 0x%.8X be 0x%.8X\n", iso_td.BufferPage0, iso_td.BufferEnd);
return 1;
}
@ -1655,7 +1655,7 @@ int OHCI::OHCI_ServiceIsoTD(OHCI_ED* ed, int completion)
if (!(OHCI_BM(start_offset, TD_PSW_CC) & 0xE) ||
((relative_frame_number < frame_count) &&
!(OHCI_BM(next_offset, TD_PSW_CC) & 0xE))) {
DbgPrintf(LOG_PREFIX, "ISO_TD cc != not accessed 0x%.8x 0x%.8x\n", start_offset, next_offset);
DBG_PRINTF("ISO_TD cc != not accessed 0x%.8x 0x%.8x\n", start_offset, next_offset);
return 1;
}
@ -1758,12 +1758,12 @@ int OHCI::OHCI_ServiceIsoTD(OHCI_ED* ed, int completion)
else {
// Handle the error condition
if (ret > static_cast<ptrdiff_t>(len)) { // Sequence Error
DbgPrintf(LOG_PREFIX, "DataOverrun %d > %zu\n", ret, len);
DBG_PRINTF("DataOverrun %d > %zu\n", ret, len);
OHCI_SET_BM(iso_td.Offset[relative_frame_number], TD_PSW_CC, OHCI_CC_DATAOVERRUN);
OHCI_SET_BM(iso_td.Offset[relative_frame_number], TD_PSW_SIZE, len);
}
else if (ret >= 0) { // Sequence Error
DbgPrintf(LOG_PREFIX, "DataUnderrun %d\n", ret);
DBG_PRINTF("DataUnderrun %d\n", ret);
OHCI_SET_BM(iso_td.Offset[relative_frame_number], TD_PSW_CC, OHCI_CC_DATAUNDERRUN);
}
else {
@ -1775,12 +1775,12 @@ int OHCI::OHCI_ServiceIsoTD(OHCI_ED* ed, int completion)
break;
case USB_RET_NAK: // NAK and STALL
case USB_RET_STALL:
DbgPrintf(LOG_PREFIX, "got NAK/STALL %d\n", ret);
DBG_PRINTF("got NAK/STALL %d\n", ret);
OHCI_SET_BM(iso_td.Offset[relative_frame_number], TD_PSW_CC, OHCI_CC_STALL);
OHCI_SET_BM(iso_td.Offset[relative_frame_number], TD_PSW_SIZE, 0);
break;
default: // Unknown Error
DbgPrintf(LOG_PREFIX, "Bad device response %d\n", ret);
DBG_PRINTF("Bad device response %d\n", ret);
OHCI_SET_BM(iso_td.Offset[relative_frame_number], TD_PSW_CC, OHCI_CC_UNDEXPETEDPID);
break;
}

View File

@ -33,21 +33,21 @@
// * All rights reserved
// *
// ******************************************************************
#define _XBOXKRNL_DEFEXTRN_
#define LOG_PREFIX CXBXR_MODULE::USB
#define LOG_PREFIX CXBXR_MODULE::USB
// prevent name collisions
namespace xboxkrnl
{
#include <xboxkrnl/xboxkrnl.h> // For PKINTERRUPT, etc.
};
};
#include "USBDevice.h"
#include "OHCI.h"
#include "CxbxKrnl\EmuKrnl.h" // For EmuLog
#include "CxbxCommon.h"
#include "CxbxKrnl\EmuKrnl.h" // For EmuLog
#include "CxbxCommon.h"
#include "Logging.h"
#define SETUP_STATE_IDLE 0
@ -56,10 +56,10 @@ namespace xboxkrnl
#define SETUP_STATE_ACK 3
#define SETUP_STATE_PARAM 4
// Acknowledgment: XQEMU (GPLv2)
// https://xqemu.com/
// Acknowledgment: XQEMU (GPLv2)
// https://xqemu.com/
void USBDevice::Init()
{
@ -100,7 +100,7 @@ void USBDevice::USB_RegisterPort(USBPort* Port, int Index, int SpeedMask, USBPor
{
Port->PortIndex = Index;
Port->SpeedMask = SpeedMask;
Port->Operations = Ops;
Port->Operations = Ops;
Port->Dev = nullptr;
USB_PortLocation(Port, nullptr, Index + 1);
m_FreePorts.push_back(Port);
@ -145,13 +145,13 @@ void USBDevice::USB_Detach(USBPort* Port)
dev->State = USB_STATE_NOTATTACHED;
}
void USBDevice::USB_Wakeup(USBEndpoint* ep)
{
XboxDeviceState* dev = ep->Dev;
if (dev->RemoteWakeup && dev->Port && dev->Port->Operations->wakeup) {
dev->Port->Operations->wakeup(dev->Port);
}
void USBDevice::USB_Wakeup(USBEndpoint* ep)
{
XboxDeviceState* dev = ep->Dev;
if (dev->RemoteWakeup && dev->Port && dev->Port->Operations->wakeup) {
dev->Port->Operations->wakeup(dev->Port);
}
}
void USBDevice::USB_DeviceReset(XboxDeviceState* dev)
@ -346,7 +346,7 @@ void USBDevice::USB_DoParameter(XboxDeviceState* s, USBPacket* p)
index = (s->SetupBuffer[5] << 8) | s->SetupBuffer[4];
if (s->SetupLength > sizeof(s->DataBuffer)) {
DbgPrintf(LOG_PREFIX, "ctrl buffer too small (%d > %zu)\n", s->SetupLength, sizeof(s->DataBuffer));
DBG_PRINTF("ctrl buffer too small (%d > %zu)\n", s->SetupLength, sizeof(s->DataBuffer));
p->Status = USB_RET_STALL;
return;
}
@ -411,7 +411,7 @@ void USBDevice::USB_DoTokenSetup(XboxDeviceState* s, USBPacket* p)
}
else {
if (s->SetupLength > sizeof(s->DataBuffer)) {
DbgPrintf(LOG_PREFIX, "ctrl buffer too small (%d > %zu)\n", s->SetupLength, sizeof(s->DataBuffer));
DBG_PRINTF("ctrl buffer too small (%d > %zu)\n", s->SetupLength, sizeof(s->DataBuffer));
p->Status = USB_RET_STALL;
return;
}
@ -571,12 +571,12 @@ void USBDevice::USB_DeviceHandleAttach(XboxDeviceState* dev)
}
}
void USBDevice::USB_DeviceHandleReset(XboxDeviceState* dev)
{
USBDeviceClass* klass = dev->klass;
if (klass->handle_reset) {
klass->handle_reset(dev);
}
void USBDevice::USB_DeviceHandleReset(XboxDeviceState* dev)
{
USBDeviceClass* klass = dev->klass;
if (klass->handle_reset) {
klass->handle_reset(dev);
}
}
void USBDevice::USB_DeviceHandleControl(XboxDeviceState* dev, USBPacket* p, int request, int value, int index, int length, uint8_t* data)
@ -636,32 +636,32 @@ void USBDevice::USB_EPsetType(XboxDeviceState* dev, int pid, int ep, uint8_t typ
uep->Type = type;
}
void USBDevice::USB_EPsetIfnum(XboxDeviceState* dev, int pid, int ep, uint8_t ifnum)
{
USBEndpoint* uep = USB_GetEP(dev, pid, ep);
uep->IfNum = ifnum;
}
void USBDevice::USB_EPsetMaxPacketSize(XboxDeviceState* dev, int pid, int ep, uint16_t raw)
{
USBEndpoint* uep = USB_GetEP(dev, pid, ep);
// Dropped from XQEMU the calculation max_packet_size = size * microframes since that's only true
// for high speed (usb 2.0) devices
uep->MaxPacketSize = raw & 0x7FF;
}
void USBDevice::USB_PortLocation(USBPort* downstream, USBPort* upstream, int portnr)
{
if (upstream) {
downstream->Path = upstream->Path + '.' + std::to_string(portnr);
}
else {
downstream->Path = std::to_string(portnr);
}
}
void USBDevice::USB_EPsetIfnum(XboxDeviceState* dev, int pid, int ep, uint8_t ifnum)
{
USBEndpoint* uep = USB_GetEP(dev, pid, ep);
uep->IfNum = ifnum;
}
void USBDevice::USB_EPsetMaxPacketSize(XboxDeviceState* dev, int pid, int ep, uint16_t raw)
{
USBEndpoint* uep = USB_GetEP(dev, pid, ep);
// Dropped from XQEMU the calculation max_packet_size = size * microframes since that's only true
// for high speed (usb 2.0) devices
uep->MaxPacketSize = raw & 0x7FF;
}
void USBDevice::USB_PortLocation(USBPort* downstream, USBPort* upstream, int portnr)
{
if (upstream) {
downstream->Path = upstream->Path + '.' + std::to_string(portnr);
}
else {
downstream->Path = std::to_string(portnr);
}
}
void USBDevice::USB_DeviceAttach(XboxDeviceState* dev)
{
USBPort* port = dev->Port;
@ -674,52 +674,52 @@ void USBDevice::USB_DeviceAttach(XboxDeviceState* dev)
}
void USBDevice::USB_DeviceDetach(XboxDeviceState* dev)
{
USBPort* port = dev->Port;
assert(port != nullptr);
assert(dev->Attached);
USB_Detach(port);
{
USBPort* port = dev->Port;
assert(port != nullptr);
assert(dev->Attached);
USB_Detach(port);
dev->Attached--;
}
void USBDevice::USB_EpInit(XboxDeviceState* dev)
{
USB_EpReset(dev);
QTAILQ_INIT(&dev->EP_ctl.Queue);
for (int ep = 0; ep < USB_MAX_ENDPOINTS; ep++) {
QTAILQ_INIT(&dev->EP_in[ep].Queue);
QTAILQ_INIT(&dev->EP_out[ep].Queue);
}
}
void USBDevice::USB_EpReset(XboxDeviceState* dev)
{
dev->EP_ctl.Num = 0;
dev->EP_ctl.Type = USB_ENDPOINT_XFER_CONTROL;
dev->EP_ctl.IfNum = 0;
dev->EP_ctl.MaxPacketSize = 64;
dev->EP_ctl.Dev = dev;
dev->EP_ctl.Pipeline = false;
for (int ep = 0; ep < USB_MAX_ENDPOINTS; ep++) {
dev->EP_in[ep].Num = ep + 1;
dev->EP_out[ep].Num = ep + 1;
dev->EP_in[ep].pid = USB_TOKEN_IN;
dev->EP_out[ep].pid = USB_TOKEN_OUT;
dev->EP_in[ep].Type = USB_ENDPOINT_XFER_INVALID;
dev->EP_out[ep].Type = USB_ENDPOINT_XFER_INVALID;
dev->EP_in[ep].IfNum = USB_INTERFACE_INVALID;
dev->EP_out[ep].IfNum = USB_INTERFACE_INVALID;
dev->EP_in[ep].MaxPacketSize = 0;
dev->EP_out[ep].MaxPacketSize = 0;
dev->EP_in[ep].Dev = dev;
dev->EP_out[ep].Dev = dev;
dev->EP_in[ep].Pipeline = false;
dev->EP_out[ep].Pipeline = false;
}
}
void USBDevice::USB_EpInit(XboxDeviceState* dev)
{
USB_EpReset(dev);
QTAILQ_INIT(&dev->EP_ctl.Queue);
for (int ep = 0; ep < USB_MAX_ENDPOINTS; ep++) {
QTAILQ_INIT(&dev->EP_in[ep].Queue);
QTAILQ_INIT(&dev->EP_out[ep].Queue);
}
}
void USBDevice::USB_EpReset(XboxDeviceState* dev)
{
dev->EP_ctl.Num = 0;
dev->EP_ctl.Type = USB_ENDPOINT_XFER_CONTROL;
dev->EP_ctl.IfNum = 0;
dev->EP_ctl.MaxPacketSize = 64;
dev->EP_ctl.Dev = dev;
dev->EP_ctl.Pipeline = false;
for (int ep = 0; ep < USB_MAX_ENDPOINTS; ep++) {
dev->EP_in[ep].Num = ep + 1;
dev->EP_out[ep].Num = ep + 1;
dev->EP_in[ep].pid = USB_TOKEN_IN;
dev->EP_out[ep].pid = USB_TOKEN_OUT;
dev->EP_in[ep].Type = USB_ENDPOINT_XFER_INVALID;
dev->EP_out[ep].Type = USB_ENDPOINT_XFER_INVALID;
dev->EP_in[ep].IfNum = USB_INTERFACE_INVALID;
dev->EP_out[ep].IfNum = USB_INTERFACE_INVALID;
dev->EP_in[ep].MaxPacketSize = 0;
dev->EP_out[ep].MaxPacketSize = 0;
dev->EP_in[ep].Dev = dev;
dev->EP_out[ep].Dev = dev;
dev->EP_in[ep].Pipeline = false;
dev->EP_out[ep].Pipeline = false;
}
}
/*
* From XQEMU:
* This function creates a serial number for a usb device.
@ -741,11 +741,11 @@ void USBDevice::USB_CreateSerial(XboxDeviceState* dev, std::string&& str)
assert(index != 0 && str.empty() == false);
str += '-';
str += m_PciPath;
str += ('-' + dev->Port->Path);
str += ('-' + dev->Port->Path);
USBDesc_SetString(dev, index, std::move(str));
}
}
const USBDesc* USBDevice::USBDesc_GetUsbDeviceDesc(XboxDeviceState* dev)
{
USBDeviceClass* klass = dev->klass;
@ -768,23 +768,23 @@ void USBDevice::USBDesc_Init(XboxDeviceState* dev)
USBDesc_SetDefaults(dev);
}
void USBDevice::USBDesc_SetDefaults(XboxDeviceState* dev)
{
const USBDesc *desc = USBDesc_GetUsbDeviceDesc(dev);
assert(desc != nullptr);
switch (dev->Speed) {
case USB_SPEED_LOW:
case USB_SPEED_FULL: {
dev->Device = desc->full;
break;
}
default:
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "unknown speed parameter %d set in %s", dev->Speed, dev->ProductDesc.c_str());
}
USBDesc_SetConfig(dev, 0);
}
void USBDevice::USBDesc_SetDefaults(XboxDeviceState* dev)
{
const USBDesc *desc = USBDesc_GetUsbDeviceDesc(dev);
assert(desc != nullptr);
switch (dev->Speed) {
case USB_SPEED_LOW:
case USB_SPEED_FULL: {
dev->Device = desc->full;
break;
}
default:
EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "unknown speed parameter %d set in %s", dev->Speed, dev->ProductDesc.c_str());
}
USBDesc_SetConfig(dev, 0);
}
int USBDevice::USBDesc_SetConfig(XboxDeviceState* dev, int value)
{
int i;
@ -858,151 +858,151 @@ const USBDescIface* USBDevice::USBDesc_FindInterface(XboxDeviceState* dev, int n
return nullptr; // not found
}
void USBDevice::USBDesc_EpInit(XboxDeviceState* dev)
{
const USBDescIface *iface;
int i, e, pid, ep;
USB_EpInit(dev); // reset endpoints (because we changed descriptors in use?)
for (i = 0; i < dev->NumInterfaces; i++) {
iface = dev->Ifaces[i];
if (iface == nullptr) {
continue;
}
for (e = 0; e < iface->bNumEndpoints; e++) {
// From the standard:
// "bEndpointAddress:
// Bit 3...0: The endpoint number
// Bit 6...4: Reserved, reset to zero
// Bit 7: Direction -> 0 = OUT endpoint, 1 = IN endpoint
// bmAttributes:
// Bit 1..0: Transfer Type
// 00 = Control, 01 = Isochronous, 10 = Bulk, 11 = Interrupt. All other bits are reserved"
pid = (iface->eps[e].bEndpointAddress & USB_DIR_IN) ? USB_TOKEN_IN : USB_TOKEN_OUT;
ep = iface->eps[e].bEndpointAddress & 0xF;
USB_EPsetType(dev, pid, ep, iface->eps[e].bmAttributes & 0x03);
USB_EPsetIfnum(dev, pid, ep, iface->bInterfaceNumber);
USB_EPsetMaxPacketSize(dev, pid, ep, iface->eps[e].wMaxPacketSize);
}
}
}
int USBDevice::USBDesc_HandleControl(XboxDeviceState* dev, USBPacket *p,
int request, int value, int index, int length, uint8_t* data)
{
const USBDesc* desc = USBDesc_GetUsbDeviceDesc(dev);
int ret = -1;
assert(desc != nullptr);
switch (request) {
case DeviceOutRequest | USB_REQ_SET_ADDRESS: {
// From the standard: "This request sets the device address for all future device accesses.
// The wValue field specifies the device address to use for all subsequent accesses"
dev->Addr = value;
DbgPrintf(LOG_PREFIX, "address 0x%X set for device %s\n", dev->Addr, dev->ProductDesc.c_str());
ret = 0;
break;
}
case DeviceRequest | USB_REQ_GET_DESCRIPTOR: {
// From the standard: "This request returns the specified descriptor if the descriptor exists.
// The wValue field specifies the descriptor type in the high byte and the descriptor index in the low byte.
// The wIndex field specifies the Language ID for string descriptors or is reset to zero for other descriptors"
ret = USBDesc_HandleStandardGetDescriptor(dev, p, value, data, length);
break;
}
case DeviceRequest | USB_REQ_GET_CONFIGURATION: {
// From the standard: "This request returns the current device configuration value.
// If the returned value is zero, the device is not configured"
data[0] = dev->Config ? dev->Config->bConfigurationValue : 0;
p->ActualLength = 1;
ret = 0;
break;
}
case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: {
// From the standard: "This request sets the device configuration. The lower byte of the wValue field specifies the desired configuration.
// This configuration value must be zero or match a configuration value from a configuration descriptor"
ret = USBDesc_SetConfig(dev, value);
DbgPrintf(LOG_PREFIX, "received standard SetConfiguration() request for device at address 0x%X. Configuration selected is %d and returned %d\n",
dev->Addr, value, ret);
break;
}
case DeviceRequest | USB_REQ_GET_STATUS: {
// From the standard: "This request returns the status for the specified recipient. The Recipient bits of the bmRequestType field
// specify the desired recipient. The data returned is the current status of the specified recipient."
// From XQEMU:
/* Default state: Device behavior when this request is received while
* the device is in the Default state is not specified.
* We return the same value that a configured device would return if
* it used the first configuration. */
const USBDescConfig* config = dev->Config ? dev->Config : &dev->Device->confs[0];
data[0] = 0;
if (config->bmAttributes & 0x40) {
data[0] |= 1 << USB_DEVICE_SELF_POWERED;
}
if (dev->RemoteWakeup) {
data[0] |= 1 << USB_DEVICE_REMOTE_WAKEUP;
}
data[1] = 0x00;
p->ActualLength = 2;
ret = 0;
break;
}
case DeviceOutRequest | USB_REQ_CLEAR_FEATURE: {
// From the standard: "This request is used to clear or disable a specific feature.
// Feature selector values in wValue must be appropriate to the recipient"
if (value == USB_DEVICE_REMOTE_WAKEUP) {
dev->RemoteWakeup = 0;
ret = 0;
}
DbgPrintf(LOG_PREFIX, "received standard ClearFeature() request for device at address 0x%X. Feature selected is %d and returned %d\n",
dev->Addr, value, ret);
break;
}
case DeviceOutRequest | USB_REQ_SET_FEATURE: {
// From the standard: "This request is used to set or enable a specific feature.
// Feature selector values in wValue must be appropriate to the recipient"
if (value == USB_DEVICE_REMOTE_WAKEUP) {
dev->RemoteWakeup = 1;
ret = 0;
}
DbgPrintf(LOG_PREFIX, "received standard SetFeature() request for device at address 0x%X. Feature selected is %d and returned %d\n",
dev->Addr, value, ret);
break;
}
case InterfaceRequest | USB_REQ_GET_INTERFACE: {
// From the standard: "This request returns the selected alternate setting for the specified interface.
// wValue = Zero; wIndex = Interface"
if (index < 0 || index >= dev->NumInterfaces) {
break;
}
data[0] = dev->AltSetting[index];
p->ActualLength = 1;
ret = 0;
break;
}
case InterfaceOutRequest | USB_REQ_SET_INTERFACE: {
// From the standard: "This request allows the host to select an alternate setting for the specified interface"
// wValue = Alternative Setting; wIndex = Interface
ret = USBDesc_SetInterface(dev, index, value);
DbgPrintf(LOG_PREFIX, "received standard SetInterface() request for device at address 0x%X. Interface selected is %d, Alternative Setting \
is %d and returned %d\n", dev->Addr, index, value, ret);
break;
}
default:
break;
}
return ret;
}
void USBDevice::USBDesc_EpInit(XboxDeviceState* dev)
{
const USBDescIface *iface;
int i, e, pid, ep;
USB_EpInit(dev); // reset endpoints (because we changed descriptors in use?)
for (i = 0; i < dev->NumInterfaces; i++) {
iface = dev->Ifaces[i];
if (iface == nullptr) {
continue;
}
for (e = 0; e < iface->bNumEndpoints; e++) {
// From the standard:
// "bEndpointAddress:
// Bit 3...0: The endpoint number
// Bit 6...4: Reserved, reset to zero
// Bit 7: Direction -> 0 = OUT endpoint, 1 = IN endpoint
// bmAttributes:
// Bit 1..0: Transfer Type
// 00 = Control, 01 = Isochronous, 10 = Bulk, 11 = Interrupt. All other bits are reserved"
pid = (iface->eps[e].bEndpointAddress & USB_DIR_IN) ? USB_TOKEN_IN : USB_TOKEN_OUT;
ep = iface->eps[e].bEndpointAddress & 0xF;
USB_EPsetType(dev, pid, ep, iface->eps[e].bmAttributes & 0x03);
USB_EPsetIfnum(dev, pid, ep, iface->bInterfaceNumber);
USB_EPsetMaxPacketSize(dev, pid, ep, iface->eps[e].wMaxPacketSize);
}
}
}
int USBDevice::USBDesc_HandleControl(XboxDeviceState* dev, USBPacket *p,
int request, int value, int index, int length, uint8_t* data)
{
const USBDesc* desc = USBDesc_GetUsbDeviceDesc(dev);
int ret = -1;
assert(desc != nullptr);
switch (request) {
case DeviceOutRequest | USB_REQ_SET_ADDRESS: {
// From the standard: "This request sets the device address for all future device accesses.
// The wValue field specifies the device address to use for all subsequent accesses"
dev->Addr = value;
DBG_PRINTF("address 0x%X set for device %s\n", dev->Addr, dev->ProductDesc.c_str());
ret = 0;
break;
}
case DeviceRequest | USB_REQ_GET_DESCRIPTOR: {
// From the standard: "This request returns the specified descriptor if the descriptor exists.
// The wValue field specifies the descriptor type in the high byte and the descriptor index in the low byte.
// The wIndex field specifies the Language ID for string descriptors or is reset to zero for other descriptors"
ret = USBDesc_HandleStandardGetDescriptor(dev, p, value, data, length);
break;
}
case DeviceRequest | USB_REQ_GET_CONFIGURATION: {
// From the standard: "This request returns the current device configuration value.
// If the returned value is zero, the device is not configured"
data[0] = dev->Config ? dev->Config->bConfigurationValue : 0;
p->ActualLength = 1;
ret = 0;
break;
}
case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: {
// From the standard: "This request sets the device configuration. The lower byte of the wValue field specifies the desired configuration.
// This configuration value must be zero or match a configuration value from a configuration descriptor"
ret = USBDesc_SetConfig(dev, value);
DBG_PRINTF("received standard SetConfiguration() request for device at address 0x%X. Configuration selected is %d and returned %d\n",
dev->Addr, value, ret);
break;
}
case DeviceRequest | USB_REQ_GET_STATUS: {
// From the standard: "This request returns the status for the specified recipient. The Recipient bits of the bmRequestType field
// specify the desired recipient. The data returned is the current status of the specified recipient."
// From XQEMU:
/* Default state: Device behavior when this request is received while
* the device is in the Default state is not specified.
* We return the same value that a configured device would return if
* it used the first configuration. */
const USBDescConfig* config = dev->Config ? dev->Config : &dev->Device->confs[0];
data[0] = 0;
if (config->bmAttributes & 0x40) {
data[0] |= 1 << USB_DEVICE_SELF_POWERED;
}
if (dev->RemoteWakeup) {
data[0] |= 1 << USB_DEVICE_REMOTE_WAKEUP;
}
data[1] = 0x00;
p->ActualLength = 2;
ret = 0;
break;
}
case DeviceOutRequest | USB_REQ_CLEAR_FEATURE: {
// From the standard: "This request is used to clear or disable a specific feature.
// Feature selector values in wValue must be appropriate to the recipient"
if (value == USB_DEVICE_REMOTE_WAKEUP) {
dev->RemoteWakeup = 0;
ret = 0;
}
DBG_PRINTF("received standard ClearFeature() request for device at address 0x%X. Feature selected is %d and returned %d\n",
dev->Addr, value, ret);
break;
}
case DeviceOutRequest | USB_REQ_SET_FEATURE: {
// From the standard: "This request is used to set or enable a specific feature.
// Feature selector values in wValue must be appropriate to the recipient"
if (value == USB_DEVICE_REMOTE_WAKEUP) {
dev->RemoteWakeup = 1;
ret = 0;
}
DBG_PRINTF("received standard SetFeature() request for device at address 0x%X. Feature selected is %d and returned %d\n",
dev->Addr, value, ret);
break;
}
case InterfaceRequest | USB_REQ_GET_INTERFACE: {
// From the standard: "This request returns the selected alternate setting for the specified interface.
// wValue = Zero; wIndex = Interface"
if (index < 0 || index >= dev->NumInterfaces) {
break;
}
data[0] = dev->AltSetting[index];
p->ActualLength = 1;
ret = 0;
break;
}
case InterfaceOutRequest | USB_REQ_SET_INTERFACE: {
// From the standard: "This request allows the host to select an alternate setting for the specified interface"
// wValue = Alternative Setting; wIndex = Interface
ret = USBDesc_SetInterface(dev, index, value);
DBG_PRINTF("received standard SetInterface() request for device at address 0x%X. Interface selected is %d, Alternative Setting \
is %d and returned %d\n", dev->Addr, index, value, ret);
break;
}
default:
break;
}
return ret;
}
int USBDevice::USBDesc_HandleStandardGetDescriptor(XboxDeviceState* dev, USBPacket* p,
int value, uint8_t* dest, size_t len)
{
@ -1020,7 +1020,7 @@ int USBDevice::USBDesc_HandleStandardGetDescriptor(XboxDeviceState* dev, USBPack
switch (type) {
case USB_DT_DEVICE: {
ret = USB_ReadDeviceDesc(&desc->id, dev->Device, buf, sizeof(buf));
DbgPrintf(LOG_PREFIX, "read operation of device descriptor of device 0x%X returns %d\n", dev->Addr, ret);
DBG_PRINTF("read operation of device descriptor of device 0x%X returns %d\n", dev->Addr, ret);
break;
}
@ -1028,13 +1028,13 @@ int USBDevice::USBDesc_HandleStandardGetDescriptor(XboxDeviceState* dev, USBPack
if (index < dev->Device->bNumConfigurations) {
ret = USB_ReadConfigurationDesc(dev->Device->confs + index, flags, buf, sizeof(buf));
}
DbgPrintf(LOG_PREFIX, "read operation of configuration descriptor %d of device 0x%X returns %d\n", index, dev->Addr, ret);
DBG_PRINTF("read operation of configuration descriptor %d of device 0x%X returns %d\n", index, dev->Addr, ret);
break;
}
case USB_DT_STRING: {
ret = USB_ReadStringDesc(dev, index, buf, sizeof(buf));
DbgPrintf(LOG_PREFIX, "read operation of string descriptor %d of device 0x%X returns %d\n", index, dev->Addr, ret);
DBG_PRINTF("read operation of string descriptor %d of device 0x%X returns %d\n", index, dev->Addr, ret);
break;
}
@ -1057,40 +1057,40 @@ int USBDevice::USBDesc_HandleStandardGetDescriptor(XboxDeviceState* dev, USBPack
return ret;
}
int USBDevice::USB_ReadDeviceDesc(const USBDescID* id, const USBDescDevice* dev, uint8_t* dest, size_t len)
{
uint8_t bLength = 0x12; // a device descriptor is 18 bytes large
USBDescriptor* d = reinterpret_cast<USBDescriptor*>(dest);
if (len < bLength) {
return -1;
}
d->bLength = bLength;
d->bDescriptorType = USB_DT_DEVICE;
d->u.device.bcdUSB_lo = GET_WORD_LOW(dev->bcdUSB);
d->u.device.bcdUSB_hi = GET_WORD_HIGH(dev->bcdUSB);
d->u.device.bDeviceClass = dev->bDeviceClass;
d->u.device.bDeviceSubClass = dev->bDeviceSubClass;
d->u.device.bDeviceProtocol = dev->bDeviceProtocol;
d->u.device.bMaxPacketSize0 = dev->bMaxPacketSize0;
d->u.device.idVendor_lo = GET_WORD_LOW(id->idVendor);
d->u.device.idVendor_hi = GET_WORD_HIGH(id->idVendor);
d->u.device.idProduct_lo = GET_WORD_LOW(id->idProduct);
d->u.device.idProduct_hi = GET_WORD_HIGH(id->idProduct);
d->u.device.bcdDevice_lo = GET_WORD_LOW(id->bcdDevice);
d->u.device.bcdDevice_hi = GET_WORD_HIGH(id->bcdDevice);
d->u.device.iManufacturer = id->iManufacturer;
d->u.device.iProduct = id->iProduct;
d->u.device.iSerialNumber = id->iSerialNumber;
d->u.device.bNumConfigurations = dev->bNumConfigurations;
return bLength;
}
int USBDevice::USB_ReadDeviceDesc(const USBDescID* id, const USBDescDevice* dev, uint8_t* dest, size_t len)
{
uint8_t bLength = 0x12; // a device descriptor is 18 bytes large
USBDescriptor* d = reinterpret_cast<USBDescriptor*>(dest);
if (len < bLength) {
return -1;
}
d->bLength = bLength;
d->bDescriptorType = USB_DT_DEVICE;
d->u.device.bcdUSB_lo = GET_WORD_LOW(dev->bcdUSB);
d->u.device.bcdUSB_hi = GET_WORD_HIGH(dev->bcdUSB);
d->u.device.bDeviceClass = dev->bDeviceClass;
d->u.device.bDeviceSubClass = dev->bDeviceSubClass;
d->u.device.bDeviceProtocol = dev->bDeviceProtocol;
d->u.device.bMaxPacketSize0 = dev->bMaxPacketSize0;
d->u.device.idVendor_lo = GET_WORD_LOW(id->idVendor);
d->u.device.idVendor_hi = GET_WORD_HIGH(id->idVendor);
d->u.device.idProduct_lo = GET_WORD_LOW(id->idProduct);
d->u.device.idProduct_hi = GET_WORD_HIGH(id->idProduct);
d->u.device.bcdDevice_lo = GET_WORD_LOW(id->bcdDevice);
d->u.device.bcdDevice_hi = GET_WORD_HIGH(id->bcdDevice);
d->u.device.iManufacturer = id->iManufacturer;
d->u.device.iProduct = id->iProduct;
d->u.device.iSerialNumber = id->iSerialNumber;
d->u.device.bNumConfigurations = dev->bNumConfigurations;
return bLength;
}
int USBDevice::USB_ReadConfigurationDesc(const USBDescConfig* conf, int flags, uint8_t* dest, size_t len)
{
uint8_t bLength = 0x09; // a configuration descriptor is 9 bytes large
@ -1102,7 +1102,7 @@ int USBDevice::USB_ReadConfigurationDesc(const USBDescConfig* conf, int flags, u
return -1;
}
// From the standard: "A request for a configuration descriptor returns the configuration descriptor, all interface
// From the standard: "A request for a configuration descriptor returns the configuration descriptor, all interface
// descriptors, and endpoint descriptors for all of the interfaces in a single request."
d->bLength = bLength;
@ -1138,10 +1138,10 @@ int USBDevice::USB_ReadInterfaceDesc(const USBDescIface* iface, int flags, uint8
return -1;
}
// From the standard: "The first interface descriptor follows the configuration descriptor.
// The endpoint descriptors for the first interface follow the first interface descriptor.
// If there are additional interfaces, their interface descriptor and endpoint descriptors
// follow the first interfaces endpoint descriptors. Class-specific and/or vendor-specific
// From the standard: "The first interface descriptor follows the configuration descriptor.
// The endpoint descriptors for the first interface follow the first interface descriptor.
// If there are additional interfaces, their interface descriptor and endpoint descriptors
// follow the first interfaces endpoint descriptors. Class-specific and/or vendor-specific
// descriptors follow the standard descriptors they extend or modify."
d->bLength = bLength;
@ -1175,18 +1175,18 @@ int USBDevice::USB_ReadInterfaceDesc(const USBDescIface* iface, int flags, uint8
return pos;
}
size_t USBDevice::USB_ReadOtherDesc(const USBDescOther* desc, uint8_t* dest, size_t len)
{
size_t bLength = desc->length ? desc->length : desc->data[0];
if (len < bLength) {
return -1;
}
std::memcpy(dest, desc->data, bLength);
return bLength;
}
size_t USBDevice::USB_ReadOtherDesc(const USBDescOther* desc, uint8_t* dest, size_t len)
{
size_t bLength = desc->length ? desc->length : desc->data[0];
if (len < bLength) {
return -1;
}
std::memcpy(dest, desc->data, bLength);
return bLength;
}
int USBDevice::USB_ReadEndpointDesc(const USBDescEndpoint* ep, int flags, uint8_t* dest, size_t len)
{
size_t bLength = ep->is_audio ? 0x09 : 0x07; // an endpoint descriptor is 7 bytes large (or 9 if it is an audio device)
@ -1221,7 +1221,7 @@ int USBDevice::USB_ReadEndpointDesc(const USBDescEndpoint* ep, int flags, uint8_
int USBDevice::USB_ReadStringDesc(XboxDeviceState* dev, int index, uint8_t* dest, size_t len)
{
size_t bLength, i;
size_t bLength, i;
unsigned int pos;
const char* str;
@ -1229,7 +1229,7 @@ int USBDevice::USB_ReadStringDesc(XboxDeviceState* dev, int index, uint8_t* dest
return -1;
}
// From the standard: "String index zero for all languages returns a string descriptor
// From the standard: "String index zero for all languages returns a string descriptor
// that contains an array of two-byte LANGID codes supported by the device"
if (index == 0) {
@ -1246,7 +1246,7 @@ int USBDevice::USB_ReadStringDesc(XboxDeviceState* dev, int index, uint8_t* dest
return 0;
}
// From the standard: "The UNICODE string descriptor is not NULL-terminated. The string length is
// From the standard: "The UNICODE string descriptor is not NULL-terminated. The string length is
// computed by subtracting two from the value of the first byte of the descriptor"
bLength = std::strlen(str) * 2 + 2;
@ -1261,34 +1261,34 @@ int USBDevice::USB_ReadStringDesc(XboxDeviceState* dev, int index, uint8_t* dest
}
void USBDevice::USBDesc_SetString(XboxDeviceState* dev, int index, std::string&& str)
{
USBDescString* s;
QLIST_FOREACH(s, &dev->Strings, next) {
if (s->index == index) {
break;
}
}
if (s == nullptr) {
s = new USBDescString();
s->index = index;
QLIST_INSERT_HEAD(&dev->Strings, s, next);
}
{
USBDescString* s;
QLIST_FOREACH(s, &dev->Strings, next) {
if (s->index == index) {
break;
}
}
if (s == nullptr) {
s = new USBDescString();
s->index = index;
QLIST_INSERT_HEAD(&dev->Strings, s, next);
}
s->str = str;
}
const char* USBDevice::USBDesc_GetString(XboxDeviceState* dev, int index)
{
USBDescString* s;
QLIST_FOREACH(s, &dev->Strings, next) {
if (s->index == index) {
return s->str.c_str();
}
}
{
USBDescString* s;
QLIST_FOREACH(s, &dev->Strings, next) {
if (s->index == index) {
return s->str.c_str();
}
}
return nullptr;
}

View File

@ -1,57 +1,57 @@
// 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->devices->usb->XidGamepad.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) 2018 ergo720
// *
// * All rights reserved
// *
// ******************************************************************
// 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->devices->usb->XidGamepad.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) 2018 ergo720
// *
// * All rights reserved
// *
// ******************************************************************
#define _XBOXKRNL_DEFEXTRN_
#define _XBOXKRNL_DEFEXTRN_
#define LOG_PREFIX CXBXR_MODULE::XIDCTRL
// prevent name collisions
namespace xboxkrnl
{
#include <xboxkrnl/xboxkrnl.h> // For PKINTERRUPT, etc.
// prevent name collisions
namespace xboxkrnl
{
#include <xboxkrnl/xboxkrnl.h> // For PKINTERRUPT, etc.
};
#include "XidGamepad.h"
#include "XidGamepad.h"
#include "USBDevice.h"
#include "Common/Input/InputConfig.h"
#include "Common/Input/SDL2_Device.h"
#include "OHCI.h"
#include "CxbxKrnl\EmuKrnl.h" // For EmuLog
#include "Logging.h"
#include "Logging.h"
#define USB_CLASS_XID 0x58
#define USB_DT_XID 0x42
@ -62,13 +62,13 @@ namespace xboxkrnl
// Acknowledgment: XQEMU (GPLv2)
// https://xqemu.com/
// To avoid including Xbox.h
extern USBDevice* g_USB0;
XidGamepad* g_XidControllerObjArray[4];
#pragma pack(1)
/* Class-specific xid descriptor */
@ -117,8 +117,8 @@ struct USBXIDState {
XIDGamepadOutputReport out_state_capabilities; // Get_Capabilities struct (out)
};
static const USBDescEndpoint desc_endp_xbox_gamepad[2] = {
{
static const USBDescEndpoint desc_endp_xbox_gamepad[2] = {
{
USB_DIR_IN | 0x02, // bEndpointAddress;
USB_ENDPOINT_XFER_INT, // bmAttributes;
0x20, // wMaxPacketSize;
@ -126,9 +126,9 @@ static const USBDescEndpoint desc_endp_xbox_gamepad[2] = {
0, // bRefresh;
0, // bSynchAddress
0, // is_audio
nullptr // extra
nullptr // extra
},
{
{
USB_DIR_OUT | 0x02,
USB_ENDPOINT_XFER_INT,
0x20,
@ -136,11 +136,11 @@ static const USBDescEndpoint desc_endp_xbox_gamepad[2] = {
0,
0,
0,
nullptr
}
};
static const USBDescIface desc_iface_xbox_gamepad = {
nullptr
}
};
static const USBDescIface desc_iface_xbox_gamepad = {
0, // bInterfaceNumber;
0, // bAlternateSetting;
2, // bNumEndpoints;
@ -150,8 +150,8 @@ static const USBDescIface desc_iface_xbox_gamepad = {
0, // iInterface
0, // ndesc
nullptr, // descs
desc_endp_xbox_gamepad
};
desc_endp_xbox_gamepad
};
static const USBDescConfig desc_config_xbox_gamepad = {
1, // bNumInterfaces
@ -162,7 +162,7 @@ static const USBDescConfig desc_config_xbox_gamepad = {
1, // nif
&desc_iface_xbox_gamepad
};
static const USBDescDevice desc_device_xbox_gamepad = {
0x0110, // bcdUSB
0, // bDeviceClass
@ -171,8 +171,8 @@ static const USBDescDevice desc_device_xbox_gamepad = {
0x40, // bMaxPacketSize0
1, // bNumConfigurations
&desc_config_xbox_gamepad
};
};
static const USBDesc desc_xbox_gamepad = {
{
0x045E, // idVendor
@ -183,8 +183,8 @@ static const USBDesc desc_xbox_gamepad = {
STR_SERIALNUMBER // iSerialNumber
},
&desc_device_xbox_gamepad
};
};
static const XIDDesc desc_xid_xbox_gamepad = {
0x10, // bLength
USB_DT_XID, // bDescriptorType
@ -194,8 +194,8 @@ static const XIDDesc desc_xid_xbox_gamepad = {
20, // bMaxInputReportSize
6, // bMaxOutputReportSize
{ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF } // wAlternateProductIds
};
};
int XidGamepad::Init(int port)
{
if (port > 4 || port < 1) { return -1; }
@ -312,25 +312,25 @@ int XidGamepad::UsbXid_Initfn(XboxDeviceState* dev)
}
void XidGamepad::UsbXid_HandleDestroy()
{
UsbXidReleasePort(&m_XidState->dev);
{
UsbXidReleasePort(&m_XidState->dev);
XidCleanUp();
}
void XidGamepad::UsbXid_Attach(XboxDeviceState* dev)
{
if ((dev->Port->SpeedMask & USB_SPEED_MASK_FULL)) {
dev->Speed = USB_SPEED_FULL;
}
else {
return;
}
if ((dev->Port->SpeedMask & USB_SPEED_MASK_FULL)) {
dev->Speed = USB_SPEED_FULL;
}
else {
return;
}
m_UsbDev->USBDesc_SetDefaults(dev);
}
void XidGamepad::UsbXid_HandleReset()
{
DbgPrintf(LOG_PREFIX, "reset event\n");
DBG_PRINTF("reset event\n");
}
void XidGamepad::UsbXid_HandleControl(XboxDeviceState* dev, USBPacket* p,
@ -338,7 +338,7 @@ void XidGamepad::UsbXid_HandleControl(XboxDeviceState* dev, USBPacket* p,
{
int ret = m_UsbDev->USBDesc_HandleControl(dev, p, request, value, index, length, data);
if (ret >= 0) {
DbgPrintf(LOG_PREFIX, "handled by USBDesc_HandleControl, ret is %d\n", ret);
DBG_PRINTF("handled by USBDesc_HandleControl, ret is %d\n", ret);
return;
}
@ -348,7 +348,7 @@ void XidGamepad::UsbXid_HandleControl(XboxDeviceState* dev, USBPacket* p,
// From the HID standard: "The Get_Report request allows the host to receive a report via the Control pipe.
// The wValue field specifies the Report Type in the high byte and the Report ID in the low byte. Set Report ID
// to 0 (zero) if Report IDs are not used. 01 = input, 02 = output, 03 = feature, 04-FF = reserved"
DbgPrintf(LOG_PREFIX, "GET_REPORT 0x%X\n", value);
DBG_PRINTF("GET_REPORT 0x%X\n", value);
// JayFoxRox's analysis: "This 0x0100 case is for input.
// This is the case where the Xbox wants to read input data from the controller.
// Confirmed with a real Duke controller :
@ -389,7 +389,7 @@ void XidGamepad::UsbXid_HandleControl(XboxDeviceState* dev, USBPacket* p,
// setting the state of input, output, or feature controls. The meaning of the request fields for the Set_Report
// request is the same as for the Get_Report request, however the data direction is reversed and the Report
// Data is sent from host to device."
DbgPrintf(LOG_PREFIX, "SET_REPORT 0x%X\n", value);
DBG_PRINTF("SET_REPORT 0x%X\n", value);
// JayFoxRox's analysis: "The 0x0200 case below is for output.
// This is the case where the Xbox wants to write rumble data to the controller.
// To my knowledge :
@ -419,7 +419,7 @@ void XidGamepad::UsbXid_HandleControl(XboxDeviceState* dev, USBPacket* p,
// XID-specific requests
case VendorInterfaceRequest | USB_REQ_GET_DESCRIPTOR: {
DbgPrintf(LOG_PREFIX, "GET_DESCRIPTOR 0x%x\n", value);
DBG_PRINTF("GET_DESCRIPTOR 0x%x\n", value);
if (value == 0x4200) {
assert(m_XidState->xid_desc->bLength <= length);
std::memcpy(data, m_XidState->xid_desc, m_XidState->xid_desc->bLength);
@ -433,7 +433,7 @@ void XidGamepad::UsbXid_HandleControl(XboxDeviceState* dev, USBPacket* p,
}
case VendorInterfaceRequest | XID_GET_CAPABILITIES: {
DbgPrintf(LOG_PREFIX, "XID_GET_CAPABILITIES 0x%x\n", value);
DBG_PRINTF("XID_GET_CAPABILITIES 0x%x\n", value);
if (value == 0x0100) {
if (length > m_XidState->in_state_capabilities.bLength) {
length = m_XidState->in_state_capabilities.bLength;
@ -457,7 +457,7 @@ void XidGamepad::UsbXid_HandleControl(XboxDeviceState* dev, USBPacket* p,
case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_DEVICE) << 8) | USB_REQ_GET_DESCRIPTOR: {
/* FIXME: ! */
DbgPrintf(LOG_PREFIX, "unknown xpad request 0x%X: value = 0x%X\n", request, value);
DBG_PRINTF("unknown xpad request 0x%X: value = 0x%X\n", request, value);
std::memset(data, 0x00, length);
//FIXME: Intended for the hub: usbd_get_hub_descriptor, UT_READ_CLASS?!
p->Status = USB_RET_STALL;
@ -467,14 +467,14 @@ void XidGamepad::UsbXid_HandleControl(XboxDeviceState* dev, USBPacket* p,
case ((USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT) << 8) | USB_REQ_CLEAR_FEATURE: {
/* FIXME: ! */
DbgPrintf(LOG_PREFIX, "unknown xpad request 0x%X: value = 0x%X\n", request, value);
DBG_PRINTF("unknown xpad request 0x%X: value = 0x%X\n", request, value);
std::memset(data, 0x00, length);
p->Status = USB_RET_STALL;
break;
}
default:
DbgPrintf(LOG_PREFIX, "USB stalled on request 0x%X value 0x%X\n", request, value);
DBG_PRINTF("USB stalled on request 0x%X value 0x%X\n", request, value);
p->Status = USB_RET_STALL;
assert(0);
break;
@ -548,7 +548,7 @@ void XidGamepad::UpdateForceFeedback()
// implementation is untested and could potentially contain errors
/* FIXME: Check actuator endianess */
DbgPrintf(LOG_PREFIX, "Set rumble power to left: 0x%X and right: 0x%X\n",
DBG_PRINTF("Set rumble power to left: 0x%X and right: 0x%X\n",
m_XidState->out_state.left_actuator_strength,
m_XidState->out_state.right_actuator_strength);
}

View File

@ -164,11 +164,11 @@ static void update_irq(NV2AState *d)
#include "EmuNV2A_DEBUG.cpp"
#define DEBUG_READ32(DEV) DbgPrintf(CXBXR_MODULE::X86, "Rd32 NV2A " #DEV "(0x%08X) = 0x%08X [Handled %s]\n", addr, result, DebugNV_##DEV##(addr))
#define DEBUG_READ32_UNHANDLED(DEV) { DbgPrintf(CXBXR_MODULE::X86, "Rd32 NV2A " #DEV "(0x%08X) = 0x%08X [Unhandled %s]\n", addr, result, DebugNV_##DEV##(addr)); return result; }
#define DEBUG_READ32(DEV) DBG_PRINTF_EX(CXBXR_MODULE::X86, "Rd32 NV2A " #DEV "(0x%08X) = 0x%08X [Handled %s]\n", addr, result, DebugNV_##DEV##(addr))
#define DEBUG_READ32_UNHANDLED(DEV) { DBG_PRINTF_EX(CXBXR_MODULE::X86, "Rd32 NV2A " #DEV "(0x%08X) = 0x%08X [Unhandled %s]\n", addr, result, DebugNV_##DEV##(addr)); return result; }
#define DEBUG_WRITE32(DEV) DbgPrintf(CXBXR_MODULE::X86, "Wr32 NV2A " #DEV "(0x%08X, 0x%08X) [Handled %s]\n", addr, value, DebugNV_##DEV##(addr))
#define DEBUG_WRITE32_UNHANDLED(DEV) { DbgPrintf(CXBXR_MODULE::X86, "Wr32 NV2A " #DEV "(0x%08X, 0x%08X) [Unhandled %s]\n", addr, value, DebugNV_##DEV##(addr)); return; }
#define DEBUG_WRITE32(DEV) DBG_PRINTF_EX(CXBXR_MODULE::X86, "Wr32 NV2A " #DEV "(0x%08X, 0x%08X) [Handled %s]\n", addr, value, DebugNV_##DEV##(addr))
#define DEBUG_WRITE32_UNHANDLED(DEV) { DBG_PRINTF_EX(CXBXR_MODULE::X86, "Wr32 NV2A " #DEV "(0x%08X, 0x%08X) [Unhandled %s]\n", addr, value, DebugNV_##DEV##(addr)); return; }
#define DEVICE_READ32(DEV) uint32_t EmuNV2A_##DEV##_Read32(NV2AState *d, xbaddr addr)
#define DEVICE_READ32_SWITCH() uint32_t result = 0; switch (addr)