diff --git a/src/Common/EmuEEPROM.cpp b/src/Common/EmuEEPROM.cpp index d12b537cf..e8102b666 100644 --- a/src/Common/EmuEEPROM.cpp +++ b/src/Common/EmuEEPROM.cpp @@ -34,6 +34,8 @@ // * // ****************************************************************** #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX CXBXR_MODULE::EEPR +#define LOG_PREFIX_INIT CXBXR_MODULE::INIT // prevent name collisions namespace xboxkrnl @@ -128,7 +130,7 @@ xboxkrnl::XBOX_EEPROM *CxbxRestoreEEPROM(char *szFilePath_EEPROM_bin) /* hTemplateFile */nullptr); if (hFileEEPROM == INVALID_HANDLE_VALUE) { - DbgPrintf("INIT: Couldn't create EEPROM.bin file!\n"); + DbgPrintf(LOG_PREFIX_INIT, "Couldn't create EEPROM.bin file!\n"); return nullptr; } } @@ -146,7 +148,7 @@ xboxkrnl::XBOX_EEPROM *CxbxRestoreEEPROM(char *szFilePath_EEPROM_bin) /**/nullptr); if (hFileMappingEEPROM == NULL) { - DbgPrintf("INIT: Couldn't create EEPROM.bin file mapping!\n"); + DbgPrintf(LOG_PREFIX_INIT, "Couldn't create EEPROM.bin file mapping!\n"); return nullptr; } @@ -155,7 +157,7 @@ xboxkrnl::XBOX_EEPROM *CxbxRestoreEEPROM(char *szFilePath_EEPROM_bin) unsigned int FileSize = len_li.u.LowPart; if (FileSize != 256) { - CxbxKrnlCleanup("CxbxRestoreEEPROM : EEPROM.bin file is not 256 bytes large!\n"); + CxbxKrnlCleanup(LOG_PREFIX, "%s : EEPROM.bin file is not 256 bytes large!\n", __func__); return nullptr; } @@ -167,7 +169,7 @@ xboxkrnl::XBOX_EEPROM *CxbxRestoreEEPROM(char *szFilePath_EEPROM_bin) /* dwFileOffsetLow */0, EEPROM_SIZE); if (pEEPROM == nullptr) { - DbgPrintf("INIT: Couldn't map EEPROM.bin into memory!\n"); + DbgPrintf(LOG_PREFIX_INIT, "Couldn't map EEPROM.bin into memory!\n"); return nullptr; } @@ -183,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("INIT: Initialized default EEPROM\n"); + DbgPrintf(LOG_PREFIX_INIT, "Initialized default EEPROM\n"); } else { XboxFactoryGameRegion = pEEPROM->EncryptedSettings.GameRegion; - DbgPrintf("INIT: Loaded EEPROM.bin\n"); + DbgPrintf(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 @@ -200,7 +202,7 @@ xboxkrnl::XBOX_EEPROM *CxbxRestoreEEPROM(char *szFilePath_EEPROM_bin) if (memcmp(Checksum, pEEPROM->EncryptedSettings.Checksum, 20)) { // The checksums do not match. Log this error and flash the LED (red, off, red, off) - EmuWarning("Stored and calculated checksums don't match. Possible eeprom corruption"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Stored and calculated checksums don't match. Possible eeprom corruption"); SetLEDSequence(0xA0); } diff --git a/src/Common/Input/InputConfig.cpp b/src/Common/Input/InputConfig.cpp index be2759f62..d4691385e 100644 --- a/src/Common/Input/InputConfig.cpp +++ b/src/Common/Input/InputConfig.cpp @@ -32,437 +32,438 @@ // * // * All rights reserved // * -// ****************************************************************** -#if 0 // Reenable this when LLE USB actually works -#define _XBOXKRNL_DEFEXTRN_ - +// ****************************************************************** +#if 0 // Reenable this when LLE USB actually works +#define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX CXBXR_MODULE::SDL2 + // prevent name collisions namespace xboxkrnl { #include // For PKINTERRUPT, etc. -}; - -#include "InputConfig.h" -#include "SDL2_Device.h" -#include "..\devices\usb\XidGamepad.h" -#include "..\..\CxbxKrnl\EmuKrnl.h" // For EmuWarning -#include - - -InputDeviceManager* g_InputDeviceManager = nullptr; - -InputDeviceManager::InputDeviceManager() -{ - if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) { - CxbxKrnlCleanup("Failed to initialize SDL2 input subsystem. The error was: %s\n", SDL_GetError()); - return; - } -} - -InputDeviceManager::~InputDeviceManager() -{ - SDL_Quit(); -} - -int InputDeviceManager::EnumSdl2Devices() -{ - int NumOfJoysticks; - int NumInvalidJoysticks; - SDL2Devices* pDev; - SDL_Joystick* pJoystick; - std::vector::iterator it; - - NumOfJoysticks = SDL_NumJoysticks(); - if (NumOfJoysticks < 0) { - EmuWarning("Failed to enumerate joysticks. The error was: %s", SDL_GetError()); - return 0; - } - - NumInvalidJoysticks = 0; - - for (int i = 0; i < NumOfJoysticks; i++) { - pDev = new SDL2Devices(); - pDev->m_Index = i; - m_Sdl2Devices.push_back(pDev); - } - - for (it = m_Sdl2Devices.begin(); it != m_Sdl2Devices.end();) { - pJoystick = SDL_JoystickOpen((*it)->m_Index); - if (pJoystick == nullptr) { - EmuWarning("Failed to open joystick %s. The error was %s\n", SDL_GameControllerNameForIndex((*it)->m_Index), SDL_GetError()); - delete (*it); - it = m_Sdl2Devices.erase(it); - NumInvalidJoysticks++; - } - else { - printf("Found joystick %s\n", SDL_JoystickName(pJoystick)); - (*it)->m_Joystick = pJoystick; - (*it)->m_jyID = SDL_JoystickInstanceID(pJoystick); - (*it)->m_Attached = 1; - ++it; - } - } - - return NumOfJoysticks - NumInvalidJoysticks; -} - -int InputDeviceManager::ConnectDeviceToXbox(int port, int type) -{ - int ret = -1; - std::vector::iterator it; - - if (port > 4 || port < 1) { return ret; }; - - for (it = m_Sdl2Devices.begin(); it != m_Sdl2Devices.end(); ++it) { - if ((*it)->m_Index == (port - 1)) { - --port; - break; - } - } - - if (it == m_Sdl2Devices.end()) { - EmuWarning("Attempted to connect a device not yet enumerated.\n"); - return ret; - } - - switch (type) - { - case MS_CONTROLLER_DUKE: { - if (g_HubObjArray[port] == nullptr) { - g_HubObjArray[port] = new Hub; - ret = g_HubObjArray[port]->Init(port + 1); - if (ret) { - delete g_HubObjArray[port]; - g_HubObjArray[port] = nullptr; - break; - } - if (g_XidControllerObjArray[port] == nullptr) { - g_XidControllerObjArray[port] = new XidGamepad; - ret = g_XidControllerObjArray[port]->Init(port + 1); - if (ret) { - g_HubObjArray[port]->HubDestroy(); - delete g_HubObjArray[port]; - g_HubObjArray[port] = nullptr; - delete g_XidControllerObjArray[port]; - g_XidControllerObjArray[port] = nullptr; - } - } - else { - ret = -1; - g_HubObjArray[port]->HubDestroy(); - delete g_HubObjArray[port]; - g_HubObjArray[port] = nullptr; - EmuWarning("Xid controller already present at port %d.2\n", port + 1); - } - } - else { - EmuWarning("Hub already present at port %d\n", port + 1); - } - break; - } - - case MS_CONTROLLER_S: - case LIGHT_GUN: - case STEERING_WHEEL: - case MEMORY_UNIT: - case IR_DONGLE: - case STEEL_BATTALION_CONTROLLER: { - printf("This device type is not yet supported\n"); - break; - } - - default: - EmuWarning("Attempted to attach an unknown device type\n"); - } - - if (!ret) { - (*it)->m_Type = type; - (*it)->m_Attached = 1; - } - - return ret; -} - -void InputDeviceManager::DisconnectDeviceFromXbox(int port) -{ - std::vector::iterator it; - - if (port < 1) { return; } - - for (it = m_Sdl2Devices.begin(); it != m_Sdl2Devices.end(); ++it) { - if ((*it)->m_Index == (port - 1)) { - --port; - break; - } - } - - if (it == m_Sdl2Devices.end()) { - // Not necessarily a bug. This could also be triggered by detaching an unsupported joystick - return; - } - - if (port + 1 > 4) { - delete (*it); - m_Sdl2Devices.erase(it); - return; - } - - switch ((*it)->m_Type) - { - case MS_CONTROLLER_DUKE: { - if (g_HubObjArray[port] != nullptr && g_XidControllerObjArray[port] != nullptr) { - g_HubObjArray[port]->HubDestroy(); - delete g_HubObjArray[port]; - g_HubObjArray[port] = nullptr; - delete g_XidControllerObjArray[port]; - g_XidControllerObjArray[port] = nullptr; - delete (*it); - m_Sdl2Devices.erase(it); - // Here, we could also see if there are detached devices that have a matching type and bound buttons, so that it can immediately - // be used instead of remaining inactive (example: 5 controllers and 1st is detached -> 5th can be used if it has bindings) - } - else { - EmuWarning("Attempted to disconnect a device not attached to the Xbox.\n"); - } - break; - } - - case MS_CONTROLLER_S: - case LIGHT_GUN: - case STEERING_WHEEL: - case MEMORY_UNIT: - case IR_DONGLE: - case STEEL_BATTALION_CONTROLLER: { - printf("This device type is not yet supported\n"); - break; - } - - default: - EmuWarning("Attempted to detach an unknown device type\n"); - } -} - -void InputDeviceManager::StartInputThread() -{ - std::thread(InputThread, this).detach(); -} - -void InputDeviceManager::InputThread(InputDeviceManager* pVoid) -{ - bool bContinue = true; - SDL_Event event; - - if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { - CxbxKrnlCleanup("Failed to initialize SDL2 video subsystem. The error was: %s\n", SDL_GetError()); - return; - } - - SDL_JoystickEventState(SDL_ENABLE); - - while (bContinue) - { - if (SDL_WaitEvent(&event)) - { - switch (event.type) - { - case SDL_JOYBUTTONUP: - case SDL_JOYBUTTONDOWN: { - pVoid->UpdateButtonState(event.jbutton.which, event.jbutton.button, event.jbutton.state); - break; - } - - case SDL_JOYHATMOTION: { - pVoid->UpdateHatState(event.jhat.which, event.jhat.hat, event.jhat.value); - break; - } - - case SDL_JOYAXISMOTION: { - pVoid->UpdateAxisState(event.jaxis.which, event.jaxis.axis, event.jaxis.value); - break; - } - - case SDL_JOYDEVICEADDED: { - bool found = false; - for (auto dev : pVoid->m_Sdl2Devices) { - if (dev->m_Index == event.jdevice.which) { - // already enumerated, skipping - found = true; - break; - } - } - if (!found) { - // for now we only support a single controller at port 1, more will be added later - if (!pVoid->IsValidController(event.jdevice.which) && event.jdevice.which == 0) { - pVoid->ConnectDeviceToXbox(1, MS_CONTROLLER_DUKE); - } - } - break; - } - - case SDL_JOYDEVICEREMOVED: { - pVoid->DisconnectDeviceFromXbox(event.jdevice.which + 1); - break; - } - - case SDL_QUIT: { - bContinue = false; - break; - } - - default: - break; - } - } - } -} - -void InputDeviceManager::UpdateButtonState(SDL_JoystickID id, uint8_t button, uint8_t state) -{ - SDL2Devices* ControllerObj = nullptr; - int xbox_button; - - for (auto Obj : m_Sdl2Devices) { - if (Obj->m_jyID == id) { - ControllerObj = Obj; - break; - } - } - - if (ControllerObj == nullptr) { - return; - } - - xbox_button = ControllerObj->GetBoundButton(button); - - if (xbox_button == GAMEPAD_INVALID) { - return; - } - - switch (xbox_button) - { - case GAMEPAD_A: - case GAMEPAD_B: - case GAMEPAD_X: - case GAMEPAD_Y: - case GAMEPAD_BLACK: - case GAMEPAD_WHITE: - case GAMEPAD_LEFT_TRIGGER: - case GAMEPAD_RIGHT_TRIGGER: { - ControllerObj->UpdateAnalogButtonState(xbox_button, state); - break; - } - - case GAMEPAD_BACK: - case GAMEPAD_START: - case GAMEPAD_LEFT_THUMB: - case GAMEPAD_RIGHT_THUMB: - case GAMEPAD_DPAD_UP: - case GAMEPAD_DPAD_DOWN: - case GAMEPAD_DPAD_LEFT: - case GAMEPAD_DPAD_RIGHT: { - ControllerObj->UpdateDigitalButtonState(xbox_button, state); - break; - } - - default: - break; - } -} - -void InputDeviceManager::UpdateHatState(SDL_JoystickID id, uint8_t hat_index, uint8_t state) -{ - SDL2Devices* ControllerObj = nullptr; - int xbox_button; - - for (auto Obj : m_Sdl2Devices) { - if (Obj->m_jyID == id) { - ControllerObj = Obj; - break; - } - } - - if (ControllerObj == nullptr) { - return; - } - - xbox_button = ControllerObj->GetBoundButton(hat_index + HAT_CONSTANT); - - if (xbox_button == GAMEPAD_INVALID) { - return; - } - - ControllerObj->UpdateHatState(state); -} - -void InputDeviceManager::UpdateAxisState(SDL_JoystickID id, uint8_t axis_index, int16_t state) -{ - SDL2Devices* ControllerObj = nullptr; - int xbox_button; - - for (auto Obj : m_Sdl2Devices) { - if (Obj->m_jyID == id) { - ControllerObj = Obj; - break; - } - } - - if (ControllerObj == nullptr) { - return; - } - - xbox_button = ControllerObj->GetBoundButton(axis_index); - - if (xbox_button == GAMEPAD_INVALID) { - return; - } - - ControllerObj->UpdateAxisState(xbox_button, state); -} - -int InputDeviceManager::IsValidController(int index) -{ - SDL2Devices* pDev; - SDL_Joystick* pJoystick; - - if (SDL_IsGameController(index)) { - pDev = new SDL2Devices(); - pDev->m_Index = index; - m_Sdl2Devices.push_back(pDev); - } - else { - // this joystick is not supported at the moment - return -1; - } - - pJoystick = SDL_JoystickOpen(pDev->m_Index); - if (pJoystick == nullptr) { - EmuWarning("Failed to open game controller %s. The error was %s\n", SDL_GameControllerNameForIndex(pDev->m_Index), SDL_GetError()); - delete pDev; - m_Sdl2Devices.erase(m_Sdl2Devices.begin() + index); - return -1; - } - else if (pDev->m_Index > 3) { - printf("More than 4 controllers detected. Putting game controller %s in detached state\n", SDL_JoystickName(pJoystick)); - pDev->m_Attached = 0; - return -1; - } - else { - printf("Found game controller %s\n", SDL_JoystickName(pJoystick)); - pDev->m_Joystick = pJoystick; - pDev->m_jyID = SDL_JoystickInstanceID(pJoystick); - return 0; - } -} - -SDL2Devices* InputDeviceManager::FindDeviceFromXboxPort(int port) -{ - if (port > 4 || port < 1) { return nullptr; }; - - for (auto it = m_Sdl2Devices.begin(); it != m_Sdl2Devices.end(); ++it) { - if ((*it)->m_Index == (port - 1)) { - return *it; - } - } - return nullptr; -} -#endif +}; + +#include "InputConfig.h" +#include "SDL2_Device.h" +#include "..\devices\usb\XidGamepad.h" +#include "..\..\CxbxKrnl\EmuKrnl.h" // For EmuWarning +#include + + +InputDeviceManager* g_InputDeviceManager = nullptr; + +InputDeviceManager::InputDeviceManager() +{ + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) { + CxbxKrnlCleanup(LOG_PREFIX, "Failed to initialize SDL2 input subsystem. The error was: %s\n", SDL_GetError()); + return; + } +} + +InputDeviceManager::~InputDeviceManager() +{ + SDL_Quit(); +} + +int InputDeviceManager::EnumSdl2Devices() +{ + int NumOfJoysticks; + int NumInvalidJoysticks; + SDL2Devices* pDev; + SDL_Joystick* pJoystick; + std::vector::iterator it; + + NumOfJoysticks = SDL_NumJoysticks(); + if (NumOfJoysticks < 0) { + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Failed to enumerate joysticks. The error was: %s", SDL_GetError()); + return 0; + } + + NumInvalidJoysticks = 0; + + for (int i = 0; i < NumOfJoysticks; i++) { + pDev = new SDL2Devices(); + pDev->m_Index = i; + m_Sdl2Devices.push_back(pDev); + } + + for (it = m_Sdl2Devices.begin(); it != m_Sdl2Devices.end();) { + pJoystick = SDL_JoystickOpen((*it)->m_Index); + if (pJoystick == nullptr) { + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Failed to open joystick %s. The error was %s\n", SDL_GameControllerNameForIndex((*it)->m_Index), SDL_GetError()); + delete (*it); + it = m_Sdl2Devices.erase(it); + NumInvalidJoysticks++; + } + else { + printf("Found joystick %s\n", SDL_JoystickName(pJoystick)); + (*it)->m_Joystick = pJoystick; + (*it)->m_jyID = SDL_JoystickInstanceID(pJoystick); + (*it)->m_Attached = 1; + ++it; + } + } + + return NumOfJoysticks - NumInvalidJoysticks; +} + +int InputDeviceManager::ConnectDeviceToXbox(int port, int type) +{ + int ret = -1; + std::vector::iterator it; + + if (port > 4 || port < 1) { return ret; }; + + for (it = m_Sdl2Devices.begin(); it != m_Sdl2Devices.end(); ++it) { + if ((*it)->m_Index == (port - 1)) { + --port; + break; + } + } + + if (it == m_Sdl2Devices.end()) { + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Attempted to connect a device not yet enumerated.\n"); + return ret; + } + + switch (type) + { + case MS_CONTROLLER_DUKE: { + if (g_HubObjArray[port] == nullptr) { + g_HubObjArray[port] = new Hub; + ret = g_HubObjArray[port]->Init(port + 1); + if (ret) { + delete g_HubObjArray[port]; + g_HubObjArray[port] = nullptr; + break; + } + if (g_XidControllerObjArray[port] == nullptr) { + g_XidControllerObjArray[port] = new XidGamepad; + ret = g_XidControllerObjArray[port]->Init(port + 1); + if (ret) { + g_HubObjArray[port]->HubDestroy(); + delete g_HubObjArray[port]; + g_HubObjArray[port] = nullptr; + delete g_XidControllerObjArray[port]; + g_XidControllerObjArray[port] = nullptr; + } + } + else { + ret = -1; + g_HubObjArray[port]->HubDestroy(); + delete g_HubObjArray[port]; + g_HubObjArray[port] = nullptr; + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Xid controller already present at port %d.2\n", port + 1); + } + } + else { + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Hub already present at port %d\n", port + 1); + } + break; + } + + case MS_CONTROLLER_S: + case LIGHT_GUN: + case STEERING_WHEEL: + case MEMORY_UNIT: + case IR_DONGLE: + case STEEL_BATTALION_CONTROLLER: { + printf("This device type is not yet supported\n"); + break; + } + + default: + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Attempted to attach an unknown device type\n"); + } + + if (!ret) { + (*it)->m_Type = type; + (*it)->m_Attached = 1; + } + + return ret; +} + +void InputDeviceManager::DisconnectDeviceFromXbox(int port) +{ + std::vector::iterator it; + + if (port < 1) { return; } + + for (it = m_Sdl2Devices.begin(); it != m_Sdl2Devices.end(); ++it) { + if ((*it)->m_Index == (port - 1)) { + --port; + break; + } + } + + if (it == m_Sdl2Devices.end()) { + // Not necessarily a bug. This could also be triggered by detaching an unsupported joystick + return; + } + + if (port + 1 > 4) { + delete (*it); + m_Sdl2Devices.erase(it); + return; + } + + switch ((*it)->m_Type) + { + case MS_CONTROLLER_DUKE: { + if (g_HubObjArray[port] != nullptr && g_XidControllerObjArray[port] != nullptr) { + g_HubObjArray[port]->HubDestroy(); + delete g_HubObjArray[port]; + g_HubObjArray[port] = nullptr; + delete g_XidControllerObjArray[port]; + g_XidControllerObjArray[port] = nullptr; + delete (*it); + m_Sdl2Devices.erase(it); + // Here, we could also see if there are detached devices that have a matching type and bound buttons, so that it can immediately + // be used instead of remaining inactive (example: 5 controllers and 1st is detached -> 5th can be used if it has bindings) + } + else { + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Attempted to disconnect a device not attached to the Xbox.\n"); + } + break; + } + + case MS_CONTROLLER_S: + case LIGHT_GUN: + case STEERING_WHEEL: + case MEMORY_UNIT: + case IR_DONGLE: + case STEEL_BATTALION_CONTROLLER: { + printf("This device type is not yet supported\n"); + break; + } + + default: + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Attempted to detach an unknown device type\n"); + } +} + +void InputDeviceManager::StartInputThread() +{ + std::thread(InputThread, this).detach(); +} + +void InputDeviceManager::InputThread(InputDeviceManager* pVoid) +{ + bool bContinue = true; + SDL_Event event; + + if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { + CxbxKrnlCleanup(LOG_PREFIX, "Failed to initialize SDL2 video subsystem. The error was: %s\n", SDL_GetError()); + return; + } + + SDL_JoystickEventState(SDL_ENABLE); + + while (bContinue) + { + if (SDL_WaitEvent(&event)) + { + switch (event.type) + { + case SDL_JOYBUTTONUP: + case SDL_JOYBUTTONDOWN: { + pVoid->UpdateButtonState(event.jbutton.which, event.jbutton.button, event.jbutton.state); + break; + } + + case SDL_JOYHATMOTION: { + pVoid->UpdateHatState(event.jhat.which, event.jhat.hat, event.jhat.value); + break; + } + + case SDL_JOYAXISMOTION: { + pVoid->UpdateAxisState(event.jaxis.which, event.jaxis.axis, event.jaxis.value); + break; + } + + case SDL_JOYDEVICEADDED: { + bool found = false; + for (auto dev : pVoid->m_Sdl2Devices) { + if (dev->m_Index == event.jdevice.which) { + // already enumerated, skipping + found = true; + break; + } + } + if (!found) { + // for now we only support a single controller at port 1, more will be added later + if (!pVoid->IsValidController(event.jdevice.which) && event.jdevice.which == 0) { + pVoid->ConnectDeviceToXbox(1, MS_CONTROLLER_DUKE); + } + } + break; + } + + case SDL_JOYDEVICEREMOVED: { + pVoid->DisconnectDeviceFromXbox(event.jdevice.which + 1); + break; + } + + case SDL_QUIT: { + bContinue = false; + break; + } + + default: + break; + } + } + } +} + +void InputDeviceManager::UpdateButtonState(SDL_JoystickID id, uint8_t button, uint8_t state) +{ + SDL2Devices* ControllerObj = nullptr; + int xbox_button; + + for (auto Obj : m_Sdl2Devices) { + if (Obj->m_jyID == id) { + ControllerObj = Obj; + break; + } + } + + if (ControllerObj == nullptr) { + return; + } + + xbox_button = ControllerObj->GetBoundButton(button); + + if (xbox_button == GAMEPAD_INVALID) { + return; + } + + switch (xbox_button) + { + case GAMEPAD_A: + case GAMEPAD_B: + case GAMEPAD_X: + case GAMEPAD_Y: + case GAMEPAD_BLACK: + case GAMEPAD_WHITE: + case GAMEPAD_LEFT_TRIGGER: + case GAMEPAD_RIGHT_TRIGGER: { + ControllerObj->UpdateAnalogButtonState(xbox_button, state); + break; + } + + case GAMEPAD_BACK: + case GAMEPAD_START: + case GAMEPAD_LEFT_THUMB: + case GAMEPAD_RIGHT_THUMB: + case GAMEPAD_DPAD_UP: + case GAMEPAD_DPAD_DOWN: + case GAMEPAD_DPAD_LEFT: + case GAMEPAD_DPAD_RIGHT: { + ControllerObj->UpdateDigitalButtonState(xbox_button, state); + break; + } + + default: + break; + } +} + +void InputDeviceManager::UpdateHatState(SDL_JoystickID id, uint8_t hat_index, uint8_t state) +{ + SDL2Devices* ControllerObj = nullptr; + int xbox_button; + + for (auto Obj : m_Sdl2Devices) { + if (Obj->m_jyID == id) { + ControllerObj = Obj; + break; + } + } + + if (ControllerObj == nullptr) { + return; + } + + xbox_button = ControllerObj->GetBoundButton(hat_index + HAT_CONSTANT); + + if (xbox_button == GAMEPAD_INVALID) { + return; + } + + ControllerObj->UpdateHatState(state); +} + +void InputDeviceManager::UpdateAxisState(SDL_JoystickID id, uint8_t axis_index, int16_t state) +{ + SDL2Devices* ControllerObj = nullptr; + int xbox_button; + + for (auto Obj : m_Sdl2Devices) { + if (Obj->m_jyID == id) { + ControllerObj = Obj; + break; + } + } + + if (ControllerObj == nullptr) { + return; + } + + xbox_button = ControllerObj->GetBoundButton(axis_index); + + if (xbox_button == GAMEPAD_INVALID) { + return; + } + + ControllerObj->UpdateAxisState(xbox_button, state); +} + +int InputDeviceManager::IsValidController(int index) +{ + SDL2Devices* pDev; + SDL_Joystick* pJoystick; + + if (SDL_IsGameController(index)) { + pDev = new SDL2Devices(); + pDev->m_Index = index; + m_Sdl2Devices.push_back(pDev); + } + else { + // this joystick is not supported at the moment + return -1; + } + + pJoystick = SDL_JoystickOpen(pDev->m_Index); + if (pJoystick == nullptr) { + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Failed to open game controller %s. The error was %s\n", SDL_GameControllerNameForIndex(pDev->m_Index), SDL_GetError()); + delete pDev; + m_Sdl2Devices.erase(m_Sdl2Devices.begin() + index); + return -1; + } + else if (pDev->m_Index > 3) { + printf("More than 4 controllers detected. Putting game controller %s in detached state\n", SDL_JoystickName(pJoystick)); + pDev->m_Attached = 0; + return -1; + } + else { + printf("Found game controller %s\n", SDL_JoystickName(pJoystick)); + pDev->m_Joystick = pJoystick; + pDev->m_jyID = SDL_JoystickInstanceID(pJoystick); + return 0; + } +} + +SDL2Devices* InputDeviceManager::FindDeviceFromXboxPort(int port) +{ + if (port > 4 || port < 1) { return nullptr; }; + + for (auto it = m_Sdl2Devices.begin(); it != m_Sdl2Devices.end(); ++it) { + if ((*it)->m_Index == (port - 1)) { + return *it; + } + } + return nullptr; +} +#endif diff --git a/src/Common/Logging.cpp b/src/Common/Logging.cpp index 5eb5f78b6..cd5a42271 100644 --- a/src/Common/Logging.cpp +++ b/src/Common/Logging.cpp @@ -42,35 +42,45 @@ // TODO : Use Boost.Format http://www.boost.org/doc/libs/1_53_0/libs/format/index.html thread_local std::string _logThreadPrefix; -std::atomic_bool g_EnabledModules[static_cast(_CXBXR_MODULE::MAX)] = { false }; -const char* g_EnumModules2String[static_cast(_CXBXR_MODULE::MAX)] = { - "CXBX", +std::atomic_bool g_EnabledModules[static_cast(CXBXR_MODULE::MAX)] = { false }; +const char* g_EnumModules2String[static_cast(CXBXR_MODULE::MAX)] = { + "CXBXR", "XBE", "INIT", "VMEM", "PMEM", + "GUI," + "EEPR", + "RSA", "POOLMEM", "D3D8", + "D3DST", + "D3DCVT", "DSOUND", "XAPI", "XACT", "XGRP", "XONLINE", - "XBDM", + "FS", "PSHB", + "PXSH", + "VTXSH", + "VTXB", "DINP", "XINP", + "SDL2", "FILE", - "FS", "X86", "HLE", "NET", "MCPX", "NV2A", + "SMC", "OHCI", "USB", "HUB", "XIDCTRL", + "ADM", "KRNL", "LOG", "XBOX", @@ -78,13 +88,12 @@ const char* g_EnumModules2String[static_cast(_CXBXR_MODULE::MAX)] "AV", "DBG", "EX", - "FS", + "FSC", "HAL", "IO", "KD", "KE", "KI", - "KD", "MM", "NT", "OB", diff --git a/src/Common/Logging.h b/src/Common/Logging.h index a76c39434..e763d5bd1 100644 --- a/src/Common/Logging.h +++ b/src/Common/Logging.h @@ -53,33 +53,43 @@ typedef enum class _LOG_LEVEL { typedef enum class _CXBXR_MODULE { // general - CXBX = 0, + CXBXR = 0, XBE, INIT, VMEM, PMEM, + GUI, + EEPR, + RSA, POOLMEM, D3D8, + D3DST, + D3DCVT, DSOUND, XAPI, XACT, XGRP, XONLINE, - XBDM, + FS, PSHB, + PXSH, + VTXSH, + VTXB, DINP, XINP, + SDL2, FILE, - FS, X86, HLE, NET, MCPX, NV2A, + SMC, OHCI, USB, HUB, XIDCTRL, + ADM, // kernel KRNL, LOG, @@ -88,13 +98,12 @@ typedef enum class _CXBXR_MODULE { AV, DBG, EX, - FS, + FSC, HAL, IO, KD, KE, KI, - KD, MM, NT, OB, @@ -106,8 +115,8 @@ typedef enum class _CXBXR_MODULE { MAX, }CXBXR_MODULE; -extern std::atomic_bool g_EnabledModules[static_cast(_CXBXR_MODULE::MAX)]; -extern const char* g_EnumModules2String[static_cast(_CXBXR_MODULE::MAX)]; +extern std::atomic_bool g_EnabledModules[static_cast(CXBXR_MODULE::MAX)]; +extern const char* g_EnumModules2String[static_cast(CXBXR_MODULE::MAX)]; extern std::atomic_uint g_CurrentLogLevel; // @@ -241,16 +250,6 @@ extern thread_local std::string _logThreadPrefix; // Checks if this log should be printed or not #define LOG_CHECK_ENABLED(cxbxr_module, level) \ if (g_EnabledModules[static_cast(cxbxr_module)] && static_cast(level) >= g_CurrentLogLevel) - -// Writes the log to stdout -#define LOG_WRITE(cxbxr_module, string) \ - std::cout << g_EnumModules2String[static_cast(cxbxr_module)] << ": " << string; - -// Writes the log at debug level -#define LOG_WRITE_DEBUG(cxbxr_module, string) \ - LOG_CHECK_ENABLED(cxbxr_module, LOG_LEVEL::DEBUG) { \ - LOG_WRITE(cxbxr_module, string) \ - } #define LOG_THREAD_INIT \ if (_logThreadPrefix.length() == 0) { \ @@ -319,9 +318,9 @@ extern thread_local std::string _logThreadPrefix; std::cout << _logThreadPrefix << _logFuncPrefix << " returns " << (type)r << "\n"; // LOG_FORWARD indicates that an api is implemented by a forward to another API -#define LOG_FORWARD(cxbxr_module, api) \ +#define LOG_FORWARD(cxbxr_module, api) \ + LOG_INIT \ LOG_CHECK_ENABLED(cxbxr_module, LOG_LEVEL::DEBUG) { \ - LOG_INIT \ do { if(g_bPrintfOn) { \ std::cout << _logThreadPrefix << _logFuncPrefix << " forwarding to "#api"...\n"; \ } } while (0); \ @@ -418,14 +417,14 @@ extern thread_local std::string _logThreadPrefix; #define LOG_FUNC_ONE_ARG_OUT(cxbxr_module, arg) LOG_FUNC_BEGIN(cxbxr_module) 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(cxbxr_module, r) do { LOG_CHECK_ENABLED(cxbxr_module, LOG_LEVEL::DEBUG) { LOG_FUNC_RESULT(r) return r; } } while (0) +#define RETURN(cxbxr_module, r) do { LOG_CHECK_ENABLED(cxbxr_module, 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(cxbxr_module, type, r) do { LOG_CHECK_ENABLED(cxbxr_module, LOG_LEVEL::DEBUG) { LOG_FUNC_RESULT_TYPE(type, r) return r; } } while (0) +#define RETURN_TYPE(cxbxr_module, type, r) do { LOG_CHECK_ENABLED(cxbxr_module, 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("TRAC: " ## msg, __VA_ARGS__); } } +#define LOG_ONCE(msg, ...) { static bool bFirstTime = true; if(bFirstTime) { bFirstTime = false; DbgPrintf(LOG_PREFIX, "TRAC: " ## msg, __VA_ARGS__); } } -#define LOG_XBOX_CALL(func) DbgPrintf("TRAC: Xbox " ## func ## "() call\n"); +#define LOG_XBOX_CALL(func) DbgPrintf(LOG_PREFIX, "TRAC: Xbox " ## func ## "() call\n"); #define LOG_FIRST_XBOX_CALL(func) LOG_ONCE("First Xbox " ## func ## "() call\n"); // diff --git a/src/Common/Win32/EmuShared.cpp b/src/Common/Win32/EmuShared.cpp index d28c1a3bb..4fb0a633d 100644 --- a/src/Common/Win32/EmuShared.cpp +++ b/src/Common/Win32/EmuShared.cpp @@ -86,7 +86,7 @@ void EmuShared::Init(DWORD guiProcessID) ); if(hMapObject == NULL) - CxbxKrnlCleanup("Could not map shared memory!"); + CxbxKrnlCleanup(CXBXR_MODULE::INIT, "Could not map shared memory!"); if(GetLastError() == ERROR_ALREADY_EXISTS) bRequireConstruction = false; @@ -106,7 +106,7 @@ void EmuShared::Init(DWORD guiProcessID) ); if(g_EmuShared == nullptr) - CxbxKrnlCleanup("Could not map view of shared memory!"); + CxbxKrnlCleanup(CXBXR_MODULE::INIT, "Could not map view of shared memory!"); } // ****************************************************************** diff --git a/src/Common/Win32/XBPortMapping.cpp b/src/Common/Win32/XBPortMapping.cpp index 2da0b286a..f6f71b041 100644 --- a/src/Common/Win32/XBPortMapping.cpp +++ b/src/Common/Win32/XBPortMapping.cpp @@ -34,7 +34,6 @@ // * // ****************************************************************** #define _XBOXKRNL_DEFEXTRN_ - #define LOG_PREFIX CXBXR_MODULE::XBPM #undef FIELD_OFFSET // prevent macro redefinition warnings diff --git a/src/Cxbx.h b/src/Cxbx.h index 8388c0462..19bc48e8e 100644 --- a/src/Cxbx.h +++ b/src/Cxbx.h @@ -141,9 +141,11 @@ extern volatile bool g_bPrintfOn; /*! DbgPrintf enabled if _DEBUG_TRACE is set */ #ifdef _DEBUG_TRACE - #define DbgPrintf(fmt, ...) { \ - CXBX_CHECK_INTEGRITY(); \ - if(g_bPrintfOn) printf("[0x%.4X] "##fmt, GetCurrentThreadId(), ##__VA_ARGS__); \ + #define DbgPrintf(cxbxr_module, fmt, ...) { \ + if (g_EnabledModules[static_cast(cxbxr_module)] && static_cast(LOG_LEVEL::DEBUG) >= g_CurrentLogLevel) { \ + CXBX_CHECK_INTEGRITY(); \ + if(g_bPrintfOn) printf("[0x%.4X] %s: "##fmt, GetCurrentThreadId(), g_EnumModules2String[static_cast(cxbxr_module)], ##__VA_ARGS__); \ + } \ } #else inline void null_func(...) { } diff --git a/src/Cxbx/CxbxXbdm.cpp b/src/Cxbx/CxbxXbdm.cpp index 854f87c39..8f57e3dc6 100644 --- a/src/Cxbx/CxbxXbdm.cpp +++ b/src/Cxbx/CxbxXbdm.cpp @@ -131,7 +131,7 @@ namespace xbdm { void DmSendNotificationString(LPCSTR sz) { // Just send this string to Cxbx's debug output : - DbgPrintf("%s\n", sz); + DbgPrintf(LOG_PREFIX, "%s\n", sz); } // 0x0025 (37) diff --git a/src/Cxbx/WndMain.cpp b/src/Cxbx/WndMain.cpp index 4c00ce90c..cd823415f 100644 --- a/src/Cxbx/WndMain.cpp +++ b/src/Cxbx/WndMain.cpp @@ -35,6 +35,9 @@ // * All rights reserved // * // ****************************************************************** + +#define LOG_PREFIX CXBXR_MODULE::GUI + #include "WndMain.h" #include "DlgAbout.h" #include "DlgControllerConfig.h" @@ -122,7 +125,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("Couldn't parse resolution : %s.\n", resolution); + DbgPrintf(LOG_PREFIX, "Couldn't parse resolution : %s.\n", resolution); } } diff --git a/src/CxbxKrnl/CxbxKrnl.cpp b/src/CxbxKrnl/CxbxKrnl.cpp index 6ace791a4..d220fc495 100644 --- a/src/CxbxKrnl/CxbxKrnl.cpp +++ b/src/CxbxKrnl/CxbxKrnl.cpp @@ -35,6 +35,8 @@ // ****************************************************************** #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX CXBXR_MODULE::CXBXR +#define LOG_PREFIX_INIT CXBXR_MODULE::INIT /* prevent name collisions */ namespace xboxkrnl @@ -199,7 +201,7 @@ void CxbxLaunchXbe(void(*Entry)()) } __except (EmuException(GetExceptionInformation())) { - EmuWarning("Problem with ExceptionFilter"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Problem with ExceptionFilter"); } } @@ -320,7 +322,7 @@ HANDLE CxbxRestoreContiguousMemory(char *szFilePath_memory_bin) /* hTemplateFile */nullptr); if (hFile == INVALID_HANDLE_VALUE) { - CxbxKrnlCleanup("CxbxRestoreContiguousMemory : Couldn't create memory.bin file!\n"); + CxbxKrnlCleanup(LOG_PREFIX, "%s : Couldn't create memory.bin file!\n", __func__); return nullptr; } } @@ -338,7 +340,7 @@ HANDLE CxbxRestoreContiguousMemory(char *szFilePath_memory_bin) /**/nullptr); if (hFileMapping == NULL) { - CxbxKrnlCleanup("CxbxRestoreContiguousMemory : Couldn't create contiguous memory.bin file mapping!\n"); + CxbxKrnlCleanup(LOG_PREFIX, "%s : Couldn't create contiguous memory.bin file mapping!\n", __func__); return nullptr; } @@ -347,7 +349,7 @@ HANDLE CxbxRestoreContiguousMemory(char *szFilePath_memory_bin) unsigned int FileSize = len_li.u.LowPart; if (FileSize != CHIHIRO_MEMORY_SIZE) { - CxbxKrnlCleanup("CxbxRestoreContiguousMemory : memory.bin file is not 128 MiB large!\n"); + CxbxKrnlCleanup(LOG_PREFIX, "%s : memory.bin file is not 128 MiB large!\n", __func__); return nullptr; } @@ -364,7 +366,7 @@ HANDLE CxbxRestoreContiguousMemory(char *szFilePath_memory_bin) if (memory) UnmapViewOfFile(memory); - CxbxKrnlCleanup("CxbxRestoreContiguousMemory: Couldn't map contiguous memory.bin to 0x80000000!"); + CxbxKrnlCleanup(LOG_PREFIX, "%s: Couldn't map contiguous memory.bin to 0x80000000!", __func__); return nullptr; } @@ -401,7 +403,7 @@ HANDLE CxbxRestoreContiguousMemory(char *szFilePath_memory_bin) if (tiled_memory) UnmapViewOfFile(tiled_memory); - CxbxKrnlCleanup("CxbxRestoreContiguousMemory: Couldn't map contiguous memory.bin into tiled memory at 0xF0000000!"); + CxbxKrnlCleanup(LOG_PREFIX, "%s: Couldn't map contiguous memory.bin into tiled memory at 0xF0000000!", __func__); return nullptr; } @@ -436,7 +438,7 @@ HANDLE CxbxRestorePageTablesMemory(char* szFilePath_page_tables) /* hTemplateFile */nullptr); if (hFile == INVALID_HANDLE_VALUE) { - CxbxKrnlCleanup("CxbxRestorePageTablesMemory : Couldn't create PageTables.bin file!\n"); + CxbxKrnlCleanup(LOG_PREFIX, "%s : Couldn't create PageTables.bin file!\n", __func__); } } @@ -453,7 +455,7 @@ HANDLE CxbxRestorePageTablesMemory(char* szFilePath_page_tables) /**/nullptr); if (hFileMapping == NULL) { - CxbxKrnlCleanup("CxbxRestorePageTablesMemory : Couldn't create PageTables.bin file mapping!\n"); + CxbxKrnlCleanup(LOG_PREFIX, "%s : Couldn't create PageTables.bin file mapping!\n", __func__); } LARGE_INTEGER len_li; @@ -461,7 +463,7 @@ HANDLE CxbxRestorePageTablesMemory(char* szFilePath_page_tables) unsigned int FileSize = len_li.u.LowPart; if (FileSize != PAGE_TABLES_SIZE) { - CxbxKrnlCleanup("CxbxRestorePageTablesMemory : PageTables.bin file is not 4 MiB large!\n"); + CxbxKrnlCleanup(LOG_PREFIX, "%s : PageTables.bin file is not 4 MiB large!\n", __func__); } // Map PageTables.bin contents into memory : @@ -477,7 +479,7 @@ HANDLE CxbxRestorePageTablesMemory(char* szFilePath_page_tables) if (memory) UnmapViewOfFile(memory); - CxbxKrnlCleanup("CxbxRestorePageTablesMemory: Couldn't map PageTables.bin to 0xC0000000!"); + CxbxKrnlCleanup(LOG_PREFIX, "%s: Couldn't map PageTables.bin to 0xC0000000!", __func__); } printf("[0x%.4X] INIT: Mapped %d MiB of Xbox page tables memory at 0x%.8X to 0x%.8X\n", @@ -496,7 +498,7 @@ HANDLE CxbxRestorePageTablesMemory(char* szFilePath_page_tables) #pragma optimize("", off) -void CxbxPopupMessage(CxbxMsgDlgIcon icon, const char *message, ...) +void CxbxPopupMessage(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, CxbxMsgDlgIcon icon, const char *message, ...) { char Buffer[1024]; va_list argp; @@ -526,7 +528,8 @@ void CxbxPopupMessage(CxbxMsgDlgIcon icon, const char *message, ...) vsprintf(Buffer, message, argp); va_end(argp); - EmuWarning("Popup : %s\n", Buffer); + EmuLog(cxbxr_module, level, "Popup : %s\n", Buffer); + MessageBox(NULL, Buffer, TEXT("Cxbx-Reloaded"), uType); } @@ -935,7 +938,7 @@ void CxbxKrnlMain(int argc, char* argv[]) Sleep(100); } if (!isReady) { - EmuWarning("GUI process is not ready!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "GUI process is not ready!"); int mbRet = MessageBox(NULL, "GUI process is not ready, do you wish to retry?", TEXT("Cxbx-Reloaded"), MB_ICONWARNING | MB_RETRYCANCEL | MB_TOPMOST | MB_SETFOREGROUND); if (mbRet == IDRETRY) { @@ -1019,14 +1022,14 @@ void CxbxKrnlMain(int argc, char* argv[]) // verify base of code of our executable is 0x00001000 if (ExeNtHeader->OptionalHeader.BaseOfCode != CXBX_BASE_OF_CODE) { - CxbxPopupMessage(CxbxMsgDlgIcon_Error, "Cxbx-Reloaded executuable requires it's base of code to be 0x00001000"); + CxbxPopupMessage(LOG_PREFIX, LOG_LEVEL::FATAL, CxbxMsgDlgIcon_Error, "Cxbx-Reloaded executuable requires it's base of code to be 0x00001000"); return; // TODO : Halt(0); } // verify virtual_memory_placeholder is located at 0x00011000 if ((UINT_PTR)(&(virtual_memory_placeholder[0])) != (XBE_IMAGE_BASE + CXBX_BASE_OF_CODE)) { - CxbxPopupMessage(CxbxMsgDlgIcon_Error, "virtual_memory_placeholder is not loaded to base address 0x00011000 (which is a requirement for Xbox emulation)"); + CxbxPopupMessage(LOG_PREFIX, LOG_LEVEL::FATAL, CxbxMsgDlgIcon_Error, "virtual_memory_placeholder is not loaded to base address 0x00011000 (which is a requirement for Xbox emulation)"); return; // TODO : Halt(0); } @@ -1067,7 +1070,7 @@ void CxbxKrnlMain(int argc, char* argv[]) EEPROM = CxbxRestoreEEPROM(szFilePath_EEPROM_bin); if (EEPROM == nullptr) { - CxbxPopupMessage(CxbxMsgDlgIcon_Error, "Couldn't init EEPROM!"); + CxbxPopupMessage(LOG_PREFIX, LOG_LEVEL::FATAL, CxbxMsgDlgIcon_Error, "Couldn't init EEPROM!"); return; // TODO : Halt(0); } @@ -1082,7 +1085,7 @@ void CxbxKrnlMain(int argc, char* argv[]) CxbxKrnl_Xbe = new Xbe(szFilePath_Xbe, false); // TODO : Instead of using the Xbe class, port Dxbx _ReadXbeBlock() if (CxbxKrnl_Xbe->HasFatalError()) { - CxbxKrnlCleanup(CxbxKrnl_Xbe->GetError().c_str()); + CxbxKrnlCleanup(LOG_PREFIX, CxbxKrnl_Xbe->GetError().c_str()); return; } @@ -1091,7 +1094,7 @@ void CxbxKrnlMain(int argc, char* argv[]) printf("[0x%X] INIT: Valid xbe signature. Xbe is legit\n", GetCurrentThreadId()); } else { - EmuWarning("Invalid xbe signature. Homebrew, tampered or pirated xbe?"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Invalid xbe signature. Homebrew, tampered or pirated xbe?"); } // Check the integrity of the xbe sections @@ -1104,7 +1107,7 @@ void CxbxKrnlMain(int argc, char* argv[]) CalcSHA1Hash(SHADigest, CxbxKrnl_Xbe->m_bzSection[sectionIndex], RawSize); if (memcmp(SHADigest, (CxbxKrnl_Xbe->m_SectionHeader)[sectionIndex].bzSectionDigest, A_SHA_DIGEST_LEN) != 0) { - EmuWarning("SHA hash of section %s doesn't match, possible section corruption", CxbxKrnl_Xbe->m_szSectionName[sectionIndex]); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "SHA hash of section %s doesn't match, possible section corruption", CxbxKrnl_Xbe->m_szSectionName[sectionIndex]); } else { printf("[0x%X] INIT: SHA hash check of section %s successful\n", GetCurrentThreadId(), CxbxKrnl_Xbe->m_szSectionName[sectionIndex]); @@ -1139,7 +1142,7 @@ void CxbxKrnlMain(int argc, char* argv[]) if ((sectionHeaders[i].Flags & XBEIMAGE_SECTION_PRELOAD) != 0) { NTSTATUS result = xboxkrnl::XeLoadSection(§ionHeaders[i]); if (FAILED(result)) { - CxbxKrnlCleanup("Failed to preload XBE section: %s", CxbxKrnl_Xbe->m_szSectionName[i]); + CxbxKrnlCleanup(LOG_PREFIX, "Failed to preload XBE section: %s", CxbxKrnl_Xbe->m_szSectionName[i]); } } } @@ -1214,7 +1217,7 @@ void LoadXboxKeys(std::string path) memcpy(xboxkrnl::XboxCertificateKey, &keys[1], xboxkrnl::XBOX_KEY_LENGTH); } else { - EmuWarning("Keys.bin has an incorrect filesize. Should be %d bytes", xboxkrnl::XBOX_KEY_LENGTH * 2); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Keys.bin has an incorrect filesize. Should be %d bytes", xboxkrnl::XBOX_KEY_LENGTH * 2); } fclose(fp); @@ -1222,7 +1225,7 @@ void LoadXboxKeys(std::string path) } // If we didn't already exit the function, keys.bin could not be loaded - EmuWarning("Failed to load Keys.bin. Cxbx-Reloaded will be unable to read Save Data from a real Xbox"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Failed to load Keys.bin. Cxbx-Reloaded will be unable to read Save Data from a real Xbox"); } __declspec(noreturn) void CxbxKrnlInit @@ -1255,7 +1258,7 @@ __declspec(noreturn) void CxbxKrnlInit CxbxInitPerformanceCounters(); Timer_Init(); #ifdef _DEBUG -// CxbxPopupMessage("Attach a Debugger"); +// CxbxPopupMessage(LOG_PREFIX, LOG_LEVEL::INFO, "Attach a Debugger"); // Debug child processes using https://marketplace.visualstudio.com/items?itemName=GreggMiskelly.MicrosoftChildProcessDebuggingPowerTool #endif @@ -1361,7 +1364,7 @@ __declspec(noreturn) void CxbxKrnlInit CxbxRegisterDeviceHostPath(DeviceHarddisk0Partition7, CxbxBasePath + "Partition7"); // Create default symbolic links : - DbgPrintf("INIT: Creating default symbolic links.\n"); + DbgPrintf(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. @@ -1425,10 +1428,10 @@ __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("INIT: Determining CPU affinity.\n"); + DbgPrintf(LOG_PREFIX_INIT, "Determining CPU affinity.\n"); { if (!GetProcessAffinityMask(g_CurrentProcessHandle, &g_CPUXbox, &g_CPUOthers)) - CxbxKrnlCleanup("INIT: GetProcessAffinityMask failed."); + CxbxKrnlCleanup(LOG_PREFIX_INIT, "GetProcessAffinityMask failed."); // For the other threads, remove one bit from the processor mask: g_CPUOthers = ((g_CPUXbox - 1) & g_CPUXbox); @@ -1444,7 +1447,7 @@ __declspec(noreturn) void CxbxKrnlInit } // initialize graphics - DbgPrintf("INIT: Initializing render window.\n"); + DbgPrintf(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 @@ -1488,7 +1491,7 @@ __declspec(noreturn) void CxbxKrnlInit if (!bLLE_GPU) { - DbgPrintf("INIT: Initializing Direct3D.\n"); + DbgPrintf(LOG_PREFIX_INIT, "Initializing Direct3D.\n"); XTL::EmuD3DInit(); } @@ -1520,13 +1523,13 @@ __declspec(noreturn) void CxbxKrnlInit DWORD dwThreadId; HANDLE hThread = (HANDLE)_beginthreadex(NULL, NULL, CxbxKrnlInterruptThread, NULL, NULL, (uint*)&dwThreadId); - DbgPrintf("INIT: Calling XBE entry point...\n"); + DbgPrintf(LOG_PREFIX_INIT, "Calling XBE entry point...\n"); CxbxLaunchXbe(Entry); // FIXME: Wait for Cxbx to exit or error fatally Sleep(INFINITE); - DbgPrintf("INIT: XBE entry point returned\n"); + DbgPrintf(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) @@ -1540,14 +1543,14 @@ void CxbxInitFilePaths() // Make sure our data folder exists : bool result = std::experimental::filesystem::exists(szFolder_CxbxReloadedData); if (!result && !std::experimental::filesystem::create_directory(szFolder_CxbxReloadedData)) { - CxbxKrnlCleanup("CxbxInitFilePaths : Couldn't create Cxbx-Reloaded's data folder!"); + CxbxKrnlCleanup(LOG_PREFIX, "%s : Couldn't create Cxbx-Reloaded's data folder!", __func__); } // Make sure the EmuDisk folder exists std::string emuDisk = std::string(szFolder_CxbxReloadedData) + std::string("\\EmuDisk"); result = std::experimental::filesystem::exists(emuDisk); if (!result && !std::experimental::filesystem::create_directory(emuDisk)) { - CxbxKrnlCleanup("CxbxInitFilePaths : Couldn't create Cxbx-Reloaded EmuDisk folder!"); + CxbxKrnlCleanup(LOG_PREFIX, "%s : Couldn't create Cxbx-Reloaded EmuDisk folder!", __func__); } snprintf(szFilePath_EEPROM_bin, MAX_PATH, "%s\\EEPROM.bin", szFolder_CxbxReloadedData); @@ -1568,7 +1571,7 @@ void CxbxInitFilePaths() } };*/ -__declspec(noreturn) void CxbxKrnlCleanup(const char *szErrorMessage, ...) +__declspec(noreturn) void CxbxKrnlCleanup(CXBXR_MODULE cxbxr_module, const char *szErrorMessage, ...) { g_bEmuException = true; @@ -1584,7 +1587,7 @@ __declspec(noreturn) void CxbxKrnlCleanup(const char *szErrorMessage, ...) vsprintf(szBuffer2, szErrorMessage, argp); va_end(argp); - CxbxPopupMessage(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 DbgPrintf } printf("[0x%.4X] MAIN: Terminating Process\n", GetCurrentThreadId()); @@ -1614,7 +1617,7 @@ void CxbxKrnlRegisterThread(HANDLE hThread) } else { auto message = CxbxGetLastErrorString("DuplicateHandle"); - EmuWarning(message.c_str()); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, message.c_str()); } } @@ -1631,7 +1634,7 @@ void CxbxKrnlRegisterThread(HANDLE hThread) if(v == MAXIMUM_XBOX_THREADS) { - CxbxKrnlCleanup("There are too many active threads!"); + CxbxKrnlCleanup(LOG_PREFIX, "There are too many active threads!"); } } @@ -1756,13 +1759,13 @@ void CxbxKrnlPrintUEM(ULONG ErrorCode) xboxkrnl::ExSaveNonVolatileSetting(xboxkrnl::XC_MAX_ALL, Type, &Eeprom, sizeof(Eeprom)); } else { - CxbxKrnlCleanup("Could not display the fatal error screen"); + CxbxKrnlCleanup(LOG_PREFIX, "Could not display the fatal error screen"); } if (g_bIsChihiro) { // The Chihiro doesn't display the UEM - CxbxKrnlCleanup("The running Chihiro xbe has encountered a fatal error and needs to close"); + CxbxKrnlCleanup(LOG_PREFIX, "The running Chihiro xbe has encountered a fatal error and needs to close"); } g_CxbxFatalErrorCode = ErrorCode; @@ -1802,11 +1805,11 @@ void CxbxPrintUEMInfo(ULONG ErrorCode) if (it != UEMErrorTable.end()) { std::string ErrorMessage = "Fatal error. " + it->second + ". This error screen will persist indefinitely. Stop the emulation to close it"; - CxbxPopupMessage(CxbxMsgDlgIcon_Error, ErrorMessage.c_str()); + CxbxPopupMessage(LOG_PREFIX, LOG_LEVEL::FATAL, CxbxMsgDlgIcon_Error, ErrorMessage.c_str()); } else { - CxbxPopupMessage(CxbxMsgDlgIcon_Error, "Unknown fatal error. This error screen will persist indefinitely. Stop the emulation to close it"); + CxbxPopupMessage(LOG_PREFIX, LOG_LEVEL::FATAL, CxbxMsgDlgIcon_Error, "Unknown fatal error. This error screen will persist indefinitely. Stop the emulation to close it"); } } @@ -1817,7 +1820,7 @@ __declspec(noreturn) void CxbxKrnlTerminateThread() void CxbxKrnlPanic() { - CxbxKrnlCleanup("Kernel Panic!"); + CxbxKrnlCleanup(LOG_PREFIX, "Kernel Panic!"); } void CxbxConvertArgToString(std::string &dest, const char* krnlExe, const char* xbeFile, HWND hwndParent, DebugMode krnlDebug, const char* krnlDebugFile) { diff --git a/src/CxbxKrnl/CxbxKrnl.h b/src/CxbxKrnl/CxbxKrnl.h index 0fd6810a8..34960e073 100644 --- a/src/CxbxKrnl/CxbxKrnl.h +++ b/src/CxbxKrnl/CxbxKrnl.h @@ -35,7 +35,8 @@ #define CXBXKRNL_H #include "Cxbx.h" -#include "Common/Xbe.h" +#include "Common/Xbe.h" +#include "Logging.h" #undef FIELD_OFFSET // prevent macro redefinition warnings #include @@ -205,16 +206,16 @@ typedef enum _CxbxMsgDlgIcon { } CxbxMsgDlgIcon; -void CxbxPopupMessage(CxbxMsgDlgIcon icon, const char *message, ...); +void CxbxPopupMessage(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, CxbxMsgDlgIcon icon, const char *message, ...); #ifdef _DEBUG -#define LOG_TEST_CASE(message) do { static bool bTestCaseLogged = false; \ +#define LOG_TEST_CASE(cxbxr_module, message) do { static bool bTestCaseLogged = false; \ if (!bTestCaseLogged) { bTestCaseLogged = true; \ - CxbxPopupMessage(CxbxMsgDlgIcon_Info, "Please report that %s shows the following message:\nLOG_TEST_CASE: %s\nIn %s (%s line %d)", \ + CxbxPopupMessage(cxbxr_module, 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 #else -#define LOG_TEST_CASE(message) do { static bool bTestCaseLogged = false; \ +#define LOG_TEST_CASE(cxbxr_module, message) do { static bool bTestCaseLogged = false; \ if (!bTestCaseLogged) { bTestCaseLogged = true; \ printf("LOG_TEST_CASE: %s\nIn %s (%s line %d)", \ message, __func__, __FILE__, __LINE__); } } while(0) @@ -234,7 +235,7 @@ void CxbxKrnlMain(int argc, char* argv[]); __declspec(noreturn) void CxbxKrnlInit(void *pTLSData, Xbe::TLS *pTLS, Xbe::LibraryVersion *LibraryVersion, DebugMode DbgMode, const char *szDebugFilename, Xbe::Header *XbeHeader, uint32 XbeHeaderSize, void (*Entry)(), int BootFlags); /*! cleanup emulation */ -__declspec(noreturn) void CxbxKrnlCleanup(const char *szErrorMessage, ...); +__declspec(noreturn) void CxbxKrnlCleanup(CXBXR_MODULE cxbxr_module, const char *szErrorMessage, ...); /*! register a thread handle */ void CxbxKrnlRegisterThread(HANDLE hThread); diff --git a/src/CxbxKrnl/DbgConsole.cpp b/src/CxbxKrnl/DbgConsole.cpp index 34c34ce85..3235c9a8a 100644 --- a/src/CxbxKrnl/DbgConsole.cpp +++ b/src/CxbxKrnl/DbgConsole.cpp @@ -212,7 +212,7 @@ void DbgConsole::ParseCommand() else if(_stricmp(szCmd, "q") == 0 || _stricmp(szCmd, "quit") == 0 || _stricmp(szCmd, "exit") == 0) { printf("CxbxDbg: Goodbye...\n"); - CxbxKrnlCleanup(NULL); + CxbxKrnlCleanup(CXBXR_MODULE::GUI, NULL); } else if(_stricmp(szCmd, "t") == 0 || _stricmp(szCmd, "trace") == 0) { diff --git a/src/CxbxKrnl/Emu.cpp b/src/CxbxKrnl/Emu.cpp index 1c844e4c3..76f64877f 100644 --- a/src/CxbxKrnl/Emu.cpp +++ b/src/CxbxKrnl/Emu.cpp @@ -49,7 +49,6 @@ namespace xboxkrnl #include "EmuShared.h" #include "HLEIntercept.h" #include "CxbxDebugger.h" -#include "Logging.h" #ifdef _DEBUG #include @@ -103,32 +102,35 @@ std::string FormatTitleId(uint32_t title_id) } // print out a warning message to the kernel debug log file -#ifdef _DEBUG_WARNINGS -void NTAPI EmuWarning(const char *szWarningMessage, ...) +#ifdef _DEBUG_WARNINGS +void NTAPI EmuLog(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, const char *szWarningMessage, ...) { - if (szWarningMessage == NULL) { - return; - } + if (szWarningMessage == NULL) { + return; + } + + LOG_CHECK_ENABLED(cxbxr_module, level) { + if (g_bPrintfOn) { - if(g_bPrintfOn) { + va_list argp; - va_list argp; + LOG_THREAD_INIT; - LOG_THREAD_INIT; + std::cout << _logThreadPrefix << (level == LOG_LEVEL::WARNING ? "WARN -> " : "-> ") + << g_EnumModules2String[static_cast(cxbxr_module)] << ": "; - std::cout << _logThreadPrefix << "WARN: "; + va_start(argp, szWarningMessage); - va_start(argp, szWarningMessage); + vfprintf(stdout, szWarningMessage, argp); - vfprintf(stdout, szWarningMessage, argp); + va_end(argp); - va_end(argp); + fprintf(stdout, "\n"); - fprintf(stdout, "\n"); + fflush(stdout); - fflush(stdout); - - } + } + } } #endif diff --git a/src/CxbxKrnl/Emu.h b/src/CxbxKrnl/Emu.h index e4381dc25..775725a77 100644 --- a/src/CxbxKrnl/Emu.h +++ b/src/CxbxKrnl/Emu.h @@ -34,17 +34,18 @@ #ifndef EMU_H #define EMU_H -#include "Common/Xbe.h" +#include "Common/Xbe.h" +#include "Logging.h" #undef FIELD_OFFSET // prevent macro redefinition warnings #include #include -// print out a warning message to the kernel debug log file -#ifdef _DEBUG_WARNINGS -void NTAPI EmuWarning(const char *szWarningMessage, ...); -#else -inline void NTAPI EmuWarning(const char *szWarningMessage, ...) { } +// print out a log message to the kernel debug log file if level is high enough +#ifdef _DEBUG_WARNINGS +void NTAPI EmuLog(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, const char *szWarningMessage, ...); +#else +inline void NTAPI EmuLog(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, const char *szWarningMessage, ...) { } #endif std::string FormatTitleId(uint32_t title_id); diff --git a/src/CxbxKrnl/EmuD3D8.cpp b/src/CxbxKrnl/EmuD3D8.cpp index 372b838c8..dfd74f65f 100644 --- a/src/CxbxKrnl/EmuD3D8.cpp +++ b/src/CxbxKrnl/EmuD3D8.cpp @@ -34,11 +34,11 @@ // * // ****************************************************************** #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX CXBXR_MODULE::D3D8 + #include "xxhash32.h" #include -#define LOG_PREFIX CXBXR_MODULE::D3D8 - // prevent name collisions namespace xboxkrnl { @@ -226,7 +226,7 @@ g_EmuCDPD = {0}; do { \ if (FAILED(hRet)) \ if(g_bPrintfOn) \ - DbgPrintf("%s : %s D3D error (0x%.08X: %s)\n", __func__, message, hRet, D3DErrorString(hRet)); \ + DbgPrintf(LOG_PREFIX, "%s : %s D3D error (0x%.08X: %s)\n", __func__, message, hRet, D3DErrorString(hRet)); \ } while (0) #endif @@ -520,7 +520,7 @@ VOID XTL::CxbxInitWindow(bool bFullInit) if (hRenderWindowThread == NULL) { char szBuffer[1024] = { 0 }; sprintf(szBuffer, "Creating EmuRenderWindowThread Failed: %08X", GetLastError()); - CxbxPopupMessage(CxbxMsgDlgIcon_Error, szBuffer); + CxbxPopupMessage(LOG_PREFIX, LOG_LEVEL::FATAL, CxbxMsgDlgIcon_Error, szBuffer); EmuShared::Cleanup(); ExitProcess(0); } @@ -688,7 +688,7 @@ inline bool IsResourceTypeGPUReadable(const DWORD ResourceType) // assert(false); // Fixup's are not allowed to be registered break; default: - CxbxKrnlCleanup("Unhandled resource type"); + CxbxKrnlCleanup(LOG_PREFIX, "Unhandled resource type"); } return false; @@ -816,7 +816,7 @@ XTL::IDirect3DResource *GetHostResource(XTL::X_D3DResource *pXboxResource, DWORD auto key = GetHostResourceKey(pXboxResource); auto it = g_XboxDirect3DResources.find(key); if (it == g_XboxDirect3DResources.end() || !it->second.pHostResource) { - EmuWarning("GetHostResource: Resource not registered or does not have a host counterpart!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "GetHostResource: Resource not registered or does not have a host counterpart!"); return nullptr; } @@ -922,7 +922,7 @@ void SetHostResource(XTL::X_D3DResource* pXboxResource, XTL::IDirect3DResource* auto& resourceInfo = g_XboxDirect3DResources[key]; // Implicitely inserts a new entry if not already existing if (resourceInfo.pHostResource) { - EmuWarning("SetHostResource: Overwriting an existing host resource"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "SetHostResource: Overwriting an existing host resource"); } resourceInfo.pHostResource = pHostResource; @@ -1352,7 +1352,7 @@ VOID XTL::EmuD3DInit() // xbox Direct3DCreate8 returns "1" always, so we need our own ptr g_pDirect3D = Direct3DCreate(D3D_SDK_VERSION); if(g_pDirect3D == NULL) - CxbxKrnlCleanup("Could not initialize Direct3D8!"); + CxbxKrnlCleanup(LOG_PREFIX, "Could not initialize Direct3D8!"); g_pDirect3D->GetDeviceCaps(g_EmuCDPD.Adapter, g_EmuCDPD.DeviceType, &g_D3DCaps); @@ -1471,11 +1471,11 @@ static DWORD WINAPI EmuRenderWindow(LPVOID lpVoid) // initialize direct input only if LLE USB is off if (!bLLE_USB) { if (!XTL::EmuDInputInit()) { - CxbxKrnlCleanup("Could not initialize DirectInput!"); + CxbxKrnlCleanup(LOG_PREFIX, "Could not initialize DirectInput!"); } } - DbgPrintf("EmuD3D8: Message-Pump thread is running.\n"); + DbgPrintf(LOG_PREFIX, "Message-Pump thread is running.\n"); SetFocus(g_hEmuWindow); @@ -1518,7 +1518,7 @@ static DWORD WINAPI EmuRenderWindow(LPVOID lpVoid) delete dbgConsole; - CxbxKrnlCleanup(NULL); + CxbxKrnlCleanup(LOG_PREFIX, NULL); } return 0; @@ -1664,7 +1664,7 @@ static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPar case SIZE_MINIMIZED: { if(g_XBVideo.bFullScreen) - CxbxKrnlCleanup(NULL); + CxbxKrnlCleanup(LOG_PREFIX, NULL); if(!g_bEmuSuspended) { @@ -1729,7 +1729,7 @@ static DWORD WINAPI EmuUpdateTickCount(LPVOID) // since callbacks come from here InitXboxThread(g_CPUOthers); // avoid Xbox1 core for lowest possible latency - DbgPrintf("EmuD3D8: Timing thread is running.\n"); + DbgPrintf(LOG_PREFIX, "Timing thread is running.\n"); // current vertical blank count int curvb = 0; @@ -1890,18 +1890,18 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) CxbxSetThreadName("Cxbx CreateDevice Proxy"); - DbgPrintf("EmuD3D8: CreateDevice proxy thread is running.\n"); + DbgPrintf(LOG_PREFIX, "CreateDevice proxy thread is running.\n"); while(true) { // if we have been signalled, create the device with cached parameters if(g_EmuCDPD.bReady) { - DbgPrintf("EmuD3D8: CreateDevice proxy thread received request.\n"); + DbgPrintf(LOG_PREFIX, "CreateDevice proxy thread received request.\n"); // only one device should be created at once if (g_pD3DDevice != nullptr) { - DbgPrintf("EmuD3D8: CreateDevice proxy thread releasing old Device.\n"); + DbgPrintf(LOG_PREFIX, "CreateDevice proxy thread releasing old Device.\n"); g_pD3DDevice->EndScene(); @@ -1945,10 +1945,10 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) if (g_EmuCDPD.bCreate) { if(g_EmuCDPD.XboxPresentationParameters.BufferSurfaces[0] != NULL) - EmuWarning("BufferSurfaces[0] : 0x%.08X", g_EmuCDPD.XboxPresentationParameters.BufferSurfaces[0]); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "BufferSurfaces[0] : 0x%.08X", g_EmuCDPD.XboxPresentationParameters.BufferSurfaces[0]); if(g_EmuCDPD.XboxPresentationParameters.DepthStencilSurface != NULL) - EmuWarning("DepthStencilSurface : 0x%.08X", g_EmuCDPD.XboxPresentationParameters.DepthStencilSurface); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "DepthStencilSurface : 0x%.08X", g_EmuCDPD.XboxPresentationParameters.DepthStencilSurface); // Make a binary copy of the Xbox D3DPRESENT_PARAMETERS memcpy(&g_EmuCDPD.HostPresentationParameters, &(g_EmuCDPD.XboxPresentationParameters), sizeof(XTL::D3DPRESENT_PARAMETERS)); @@ -1977,7 +1977,7 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) // TODO: Enumerate maximum BackBufferCount if possible. if(g_EmuCDPD.XboxPresentationParameters.BackBufferCount > 1) { - EmuWarning("Limiting BackBufferCount to 1..."); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Limiting BackBufferCount to 1..."); g_EmuCDPD.HostPresentationParameters.BackBufferCount = 1; } @@ -1995,8 +1995,8 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) // Test-case : Galleon g_EmuCDPD.HostPresentationParameters.MultiSampleType = XTL::D3DMULTISAMPLE_2_SAMPLES; else { - // CxbxKrnlCleanup("Unknown MultiSampleType (0x%.08X)", g_EmuCDPD.XboxPresentationParameters.MultiSampleType); - EmuWarning("MultiSampleType 0x%.08X is not supported!", g_EmuCDPD.XboxPresentationParameters.MultiSampleType); + // CxbxKrnlCleanup(LOG_PREFIX, "Unknown MultiSampleType (0x%.08X)", g_EmuCDPD.XboxPresentationParameters.MultiSampleType); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "MultiSampleType 0x%.08X is not supported!", g_EmuCDPD.XboxPresentationParameters.MultiSampleType); g_EmuCDPD.HostPresentationParameters.MultiSampleType = XTL::D3DMULTISAMPLE_NONE; } }*/ @@ -2008,13 +2008,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("EmuCreateDeviceProxy: Couldn't parse resolution : %s.\n", resolution); + DbgPrintf(LOG_PREFIX, "EmuCreateDeviceProxy: Couldn't parse resolution : %s.\n", resolution); } else { if (g_EmuCDPD.HostPresentationParameters.BackBufferWidth == 640) - DbgPrintf("EmuCreateDeviceProxy: Default width wasn't updated.\n"); + DbgPrintf(LOG_PREFIX, "EmuCreateDeviceProxy: Default width wasn't updated.\n"); if (g_EmuCDPD.HostPresentationParameters.BackBufferWidth == 480) - DbgPrintf("EmuCreateDeviceProxy: Default height wasn't updated.\n"); + DbgPrintf(LOG_PREFIX, "EmuCreateDeviceProxy: Default height wasn't updated.\n"); } XTL::D3DDISPLAYMODE D3DDisplayMode; @@ -2034,13 +2034,13 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) &g_EmuCDPD.HostPresentationParameters.BackBufferHeight, szBackBufferFormat, &g_EmuCDPD.HostPresentationParameters.FullScreen_RefreshRateInHz)) { - DbgPrintf("EmuCreateDeviceProxy: Couldn't parse resolution : %s.\n", resolution); + DbgPrintf(LOG_PREFIX, "EmuCreateDeviceProxy: Couldn't parse resolution : %s.\n", resolution); } else { if (g_EmuCDPD.HostPresentationParameters.BackBufferWidth == 640) - DbgPrintf("EmuCreateDeviceProxy: Default width wasn't updated.\n"); + DbgPrintf(LOG_PREFIX, "EmuCreateDeviceProxy: Default width wasn't updated.\n"); if (g_EmuCDPD.HostPresentationParameters.BackBufferWidth == 480) - DbgPrintf("EmuCreateDeviceProxy: Default height wasn't updated.\n"); + DbgPrintf(LOG_PREFIX, "EmuCreateDeviceProxy: Default height wasn't updated.\n"); } if(strcmp(szBackBufferFormat, "x1r5g5b5") == 0) @@ -2057,14 +2057,14 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) // detect vertex processing capabilities if((g_D3DCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) && g_EmuCDPD.DeviceType == XTL::D3DDEVTYPE_HAL) { - DbgPrintf("EmuD3D8: Using hardware vertex processing\n"); + DbgPrintf(LOG_PREFIX, "Using hardware vertex processing\n"); g_EmuCDPD.BehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; g_dwVertexShaderUsage = 0; } else { - DbgPrintf("EmuD3D8: Using software vertex processing\n"); + DbgPrintf(LOG_PREFIX, "Using software vertex processing\n"); g_EmuCDPD.BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; g_dwVertexShaderUsage = D3DUSAGE_SOFTWAREPROCESSING; @@ -2114,7 +2114,7 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) DEBUG_D3DRESULT(g_EmuCDPD.hRet, "IDirect3D::CreateDevice"); if(FAILED(g_EmuCDPD.hRet)) - CxbxKrnlCleanup("IDirect3D::CreateDevice failed"); + CxbxKrnlCleanup(LOG_PREFIX, "IDirect3D::CreateDevice failed"); // Which texture formats does this device support? memset(g_bSupportsFormatSurface, false, sizeof(g_bSupportsFormatSurface)); @@ -2196,7 +2196,7 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) } if(FAILED(hRet)) - CxbxKrnlCleanup("Could not initialize DirectDraw7"); + CxbxKrnlCleanup(LOG_PREFIX, "Could not initialize DirectDraw7"); hRet = g_pDD7->GetCaps(&g_DriverCaps, nullptr); DEBUG_D3DRESULT(hRet, "g_pDD7->GetCaps"); @@ -2205,7 +2205,7 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) DEBUG_D3DRESULT(hRet, "g_pDD7->SetCooperativeLevel"); if(FAILED(hRet)) - CxbxKrnlCleanup("Could not set cooperative level"); + CxbxKrnlCleanup(LOG_PREFIX, "Could not set cooperative level"); } // Dump all supported DirectDraw FourCC format codes @@ -2218,7 +2218,7 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) g_pDD7->GetFourCCCodes(&dwCodes, lpCodes); for(DWORD v=0;vCreateIndexBuffer"); if (FAILED(hRet)) - CxbxKrnlCleanup("CxbxUpdateActiveIndexBuffer: IndexBuffer Create Failed!"); + CxbxKrnlCleanup(LOG_PREFIX, "CxbxUpdateActiveIndexBuffer: IndexBuffer Create Failed!"); } // If the data needs updating, do so @@ -2430,10 +2430,10 @@ void CxbxUpdateActiveIndexBuffer D3DLockData* pData = nullptr; indexBuffer.pHostIndexBuffer->Lock(0, 0, &pData, D3DLOCK_DISCARD); if (pData == nullptr) { - CxbxKrnlCleanup("CxbxUpdateActiveIndexBuffer: Could not lock index buffer!"); + CxbxKrnlCleanup(LOG_PREFIX, "CxbxUpdateActiveIndexBuffer: Could not lock index buffer!"); } - DbgPrintf("CxbxUpdateActiveIndexBuffer: Copying %d indices (D3DFMT_INDEX16)\n", IndexCount); + DbgPrintf(LOG_PREFIX, "CxbxUpdateActiveIndexBuffer: Copying %d indices (D3DFMT_INDEX16)\n", IndexCount); memcpy(pData, pIndexData, IndexCount * sizeof(XTL::INDEX16)); indexBuffer.pHostIndexBuffer->Unlock(); @@ -2445,7 +2445,7 @@ void CxbxUpdateActiveIndexBuffer DEBUG_D3DRESULT(hRet, "g_pD3DDevice->SetIndices"); if (FAILED(hRet)) - CxbxKrnlCleanup("CxbxUpdateActiveIndexBuffer: SetIndices Failed!"); + CxbxKrnlCleanup(LOG_PREFIX, "CxbxUpdateActiveIndexBuffer: SetIndices Failed!"); } // LTCG specific Direct3D_CreateDevice function... @@ -2691,7 +2691,7 @@ PDWORD WINAPI XTL::EMUPATCH(D3DDevice_BeginPush)(DWORD Count) if (g_pPrimaryPB != nullptr) { - EmuWarning("D3DDevice_BeginPush called without D3DDevice_EndPush in between?!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "D3DDevice_BeginPush called without D3DDevice_EndPush in between?!"); delete[] g_pPrimaryPB; // prevent a memory leak } @@ -2719,7 +2719,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_BeginPush2)(DWORD Count, DWORD** ppPush) if (g_pPrimaryPB != nullptr) { - EmuWarning("D3DDevice_BeginPush2 called without D3DDevice_EndPush in between?!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "D3DDevice_BeginPush2 called without D3DDevice_EndPush in between?!"); delete[] g_pPrimaryPB; // prevent a memory leak } @@ -2741,7 +2741,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_EndPush)(DWORD *pPush) LOG_FUNC_ONE_ARG(LOG_PREFIX, pPush); if (g_pPrimaryPB == nullptr) - EmuWarning("D3DDevice_EndPush called without preceding D3DDevice_BeginPush?!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "D3DDevice_EndPush called without preceding D3DDevice_BeginPush?!"); else { EmuExecutePushBufferRaw(g_pPrimaryPB, g_dwPrimaryPBCount * sizeof(DWORD)); @@ -2879,7 +2879,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_LoadVertexShader_4) // LOG_FUNC_ARG(Handle) // LOG_FUNC_ARG(Address) // LOG_FUNC_END; - DbgPrintf("D3DDevice_LoadVertexShader_4(Handle : %d Address : %08x);\n", Handle, Address); + DbgPrintf(LOG_PREFIX, "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) @@ -3017,13 +3017,13 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SelectVertexShader) } else { - EmuWarning("g_VertexShaderSlots[%d] = 0", Address); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "g_VertexShaderSlots[%d] = 0", Address); } } if (FAILED(hRet)) { - EmuWarning("We're lying about setting a vertext shader!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "We're lying about setting a vertext shader!"); hRet = D3D_OK; } @@ -3129,7 +3129,7 @@ XTL::X_D3DSurface* WINAPI XTL::EMUPATCH(D3DDevice_GetBackBuffer2) DEBUG_D3DRESULT(hRet, "g_pD3DDevice->GetFrontBuffer"); if (FAILED(hRet)) { - EmuWarning("Could not retrieve primary surface, using backbuffer"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Could not retrieve primary surface, using backbuffer"); SetHostSurface(pBackBuffer, nullptr); pCachedPrimarySurface->Release(); pCachedPrimarySurface = nullptr; @@ -3163,7 +3163,7 @@ XTL::X_D3DSurface* WINAPI XTL::EMUPATCH(D3DDevice_GetBackBuffer2) DEBUG_D3DRESULT(hRet, "g_pD3DDevice->GetBackBuffer"); if (FAILED(hRet)) - CxbxKrnlCleanup("Unable to retrieve back buffer"); + CxbxKrnlCleanup(LOG_PREFIX, "Unable to retrieve back buffer"); SetHostSurface(pBackBuffer, pCurrentHostBackBuffer); @@ -3189,19 +3189,19 @@ XTL::X_D3DSurface* WINAPI XTL::EMUPATCH(D3DDevice_GetBackBuffer2) // Now pXboxBackbuffer points to the requested Xbox backbuffer if (pXboxBackBuffer == nullptr) { - CxbxKrnlCleanup("D3DDevice_GetBackBuffer2: Could not get Xbox backbuffer"); + CxbxKrnlCleanup(LOG_PREFIX, "D3DDevice_GetBackBuffer2: Could not get Xbox backbuffer"); } auto pCopySrcSurface = GetHostSurface(pXboxBackBuffer, D3DUSAGE_RENDERTARGET); if (pCopySrcSurface == nullptr) { - EmuWarning("Failed to get Host Resource for Xbox Back Buffer"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Failed to get Host Resource for Xbox Back Buffer"); return pXboxBackBuffer; } D3DLOCKED_RECT copyLockedRect; HRESULT hRet = pCopySrcSurface->LockRect(©LockedRect, NULL, D3DLOCK_READONLY); if (hRet != D3D_OK) { - EmuWarning("Could not lock Host Resource for Xbox Back Buffer"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Could not lock Host Resource for Xbox Back Buffer"); return pXboxBackBuffer; } @@ -3209,7 +3209,7 @@ XTL::X_D3DSurface* WINAPI XTL::EMUPATCH(D3DDevice_GetBackBuffer2) hRet = pCopySrcSurface->GetDesc(©SurfaceDesc); if (hRet != D3D_OK) { - EmuWarning("Could not get Xbox Back Buffer Host Surface Desc"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Could not get Xbox Back Buffer Host Surface Desc"); } else { DWORD Size = copyLockedRect.Pitch * copySurfaceDesc.Height; // TODO : What about mipmap levels? // Finally, do the copy from the converted host resource to the xbox resource @@ -3329,7 +3329,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetViewport) HostViewPort.MaxZ = pViewport->MaxZ; } else { - EmuWarning("GetHostRenderTargetDimensions failed - SetViewport sets Xbox viewport instead!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "GetHostRenderTargetDimensions failed - SetViewport sets Xbox viewport instead!"); } } } @@ -3375,7 +3375,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_GetViewportOffsetAndScale) LOG_FUNC_ARG(pScale) LOG_FUNC_END; - // LOG_TEST_CASE("D3DDevice_GetViewportOffsetAndScale"); // Get us some test-cases + // LOG_TEST_CASE(LOG_PREFIX, "D3DDevice_GetViewportOffsetAndScale"); // Get us some test-cases // Test case : 007: From Russia with Love // Test case : Army Men?: Sarge's War // Test case : BeatDown - Fists of Vengeance @@ -3486,7 +3486,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreateVertexShader) LOG_FUNC_END; if (g_pD3DDevice == nullptr) { - LOG_TEST_CASE("D3DDevice_CreateVertexShader called before Direct3D_CreateDevice"); + LOG_TEST_CASE(LOG_PREFIX, "D3DDevice_CreateVertexShader called before Direct3D_CreateDevice"); // We lie to allow the game to continue for now, but it probably won't work well return STATUS_SUCCESS; } @@ -3562,11 +3562,11 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreateVertexShader) else { pRecompiledFunction = NULL; - EmuWarning("Couldn't recompile vertex shader function."); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Couldn't recompile vertex shader function."); } } - //DbgPrintf("MaxVertexShaderConst = %d\n", g_D3DCaps.MaxVertexShaderConst); + //DbgPrintf(LOG_PREFIX, "MaxVertexShaderConst = %d\n", g_D3DCaps.MaxVertexShaderConst); if (SUCCEEDED(hRet) && pRecompiledFunction != nullptr) { @@ -3662,7 +3662,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_CreateVertexShader) char pFileName[30]; static int FailedShaderCount = 0; VSH_SHADER_HEADER *pHeader = (VSH_SHADER_HEADER*)pFunction; - EmuWarning("Couldn't create vertex shader!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Couldn't create vertex shader!"); sprintf(pFileName, "failed%05d.xvu", FailedShaderCount); FILE *f = fopen(pFileName, "wb"); if(f) @@ -3751,7 +3751,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexShaderConstant) if(FAILED(hRet)) { - EmuWarning("We're lying about setting a vertex shader constant!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "We're lying about setting a vertex shader constant!"); hRet = D3D_OK; } } @@ -3862,7 +3862,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetTexture_4) // LOG_FUNC_ARG(Stage) // LOG_FUNC_ARG(pTexture) // LOG_FUNC_END; - DbgPrintf("D3DDevice_SetTexture_4(Stage : %d pTexture : %08x);\n", Stage, pTexture); + DbgPrintf(LOG_PREFIX, "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*)); @@ -3924,16 +3924,16 @@ VOID __fastcall XTL::EMUPATCH(D3DDevice_SwitchTexture) } if (Stage == -1) { - LOG_TEST_CASE("D3DDevice_SwitchTexture Unknown Method"); - EmuWarning("Unknown Method (0x%.08X)", Method); + LOG_TEST_CASE(LOG_PREFIX, "D3DDevice_SwitchTexture Unknown Method"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unknown Method (0x%.08X)", Method); } else { // Switch Texture updates the data pointer of an active texture using pushbuffer commands if (EmuD3DActiveTexture[Stage] == xbnullptr) { - LOG_TEST_CASE("D3DDevice_SwitchTexture without an active texture"); + LOG_TEST_CASE(LOG_PREFIX, "D3DDevice_SwitchTexture without an active texture"); } else { - //LOG_TEST_CASE("Using CxbxActiveTextureCopies"); + //LOG_TEST_CASE(LOG_PREFIX, "Using CxbxActiveTextureCopies"); // See https://github.com/Cxbx-Reloaded/Cxbx-Reloaded/issues/1159 // Test-case : Arena Football // Test-case : Call of Duty 2: Big Red One @@ -4089,7 +4089,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexData4f) } g_InlineVertexBuffer_Table = (struct _D3DIVB*)realloc(g_InlineVertexBuffer_Table, sizeof(struct _D3DIVB) * g_InlineVertexBuffer_TableLength); - DbgPrintf("Reallocated g_InlineVertexBuffer_Table to %d entries\n", g_InlineVertexBuffer_TableLength); + DbgPrintf(LOG_PREFIX, "Reallocated g_InlineVertexBuffer_Table to %d entries\n", g_InlineVertexBuffer_TableLength); } // Is this the initial call after D3DDevice_Begin() ? @@ -4171,7 +4171,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexData4f) // These are alright break; default: - EmuWarning("D3DDevice_SetVertexData4f unexpected FVF when selecting D3DFVF_XYZ(RHW) : %x", g_InlineVertexBuffer_FVF); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "D3DDevice_SetVertexData4f unexpected FVF when selecting D3DFVF_XYZ(RHW) : %x", g_InlineVertexBuffer_FVF); // TODO : How to resolve this? } @@ -4202,7 +4202,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexData4f) // These are alright break; default: - EmuWarning("D3DDevice_SetVertexData4f unexpected FVF when processing X_D3DVSDE_BLENDWEIGHT : %x", g_InlineVertexBuffer_FVF); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "D3DDevice_SetVertexData4f unexpected FVF when processing X_D3DVSDE_BLENDWEIGHT : %x", g_InlineVertexBuffer_FVF); g_InlineVertexBuffer_FVF &= ~D3DFVF_POSITION_MASK; // for now, remove prior position mask, leading to blending below g_InlineVertexBuffer_FVF |= D3DFVF_XYZB1; // TODO: How to select blendweight D3DFVF_XYZB2 or up? @@ -4238,7 +4238,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexData4f) case X_D3DVSDE_FOG: // Xbox extension { g_InlineVertexBuffer_Table[o].Fog = a; // TODO : What about the other (b, c and d) arguments? - EmuWarning("Host Direct3D8 doesn''t support FVF FOG"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Host Direct3D8 doesn''t support FVF FOG"); break; } @@ -4247,14 +4247,14 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexData4f) case X_D3DVSDE_BACKDIFFUSE: // Xbox extension { g_InlineVertexBuffer_Table[o].BackDiffuse = D3DCOLOR_COLORVALUE(a, b, c, d); - EmuWarning("Host Direct3D8 doesn''t support FVF BACKDIFFUSE"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Host Direct3D8 doesn''t support FVF BACKDIFFUSE"); break; } case X_D3DVSDE_BACKSPECULAR: // Xbox extension { g_InlineVertexBuffer_Table[o].BackSpecular = D3DCOLOR_COLORVALUE(a, b, c, d); - EmuWarning("Host Direct3D8 doesn''t support FVF BACKSPECULAR"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Host Direct3D8 doesn''t support FVF BACKSPECULAR"); break; } @@ -4318,7 +4318,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexData4f) } default: - EmuWarning("Unknown IVB Register : %d", Register); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unknown IVB Register : %d", Register); } } @@ -4475,7 +4475,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_Clear) if (Flags & X_D3DCLEAR_TARGET) { // TODO: D3DCLEAR_TARGET_A, *R, *G, *B don't exist on windows if ((Flags & X_D3DCLEAR_TARGET) != X_D3DCLEAR_TARGET) - EmuWarning("Unsupported : Partial D3DCLEAR_TARGET flag(s) for D3DDevice_Clear : 0x%.08X", Flags & X_D3DCLEAR_TARGET); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unsupported : Partial D3DCLEAR_TARGET flag(s) for D3DDevice_Clear : 0x%.08X", Flags & X_D3DCLEAR_TARGET); HostFlags |= D3DCLEAR_TARGET; } @@ -4485,7 +4485,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_Clear) if (g_bHasDepth) HostFlags |= D3DCLEAR_ZBUFFER; else - EmuWarning("Unsupported : D3DCLEAR_ZBUFFER flag for D3DDevice_Clear without ZBuffer"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unsupported : D3DCLEAR_ZBUFFER flag for D3DDevice_Clear without ZBuffer"); } // Only clear depth buffer and stencil if present @@ -4496,11 +4496,11 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_Clear) if (g_bHasStencil) HostFlags |= D3DCLEAR_STENCIL; else - EmuWarning("Unsupported : D3DCLEAR_STENCIL flag for D3DDevice_Clear without ZBuffer"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unsupported : D3DCLEAR_STENCIL flag for D3DDevice_Clear without ZBuffer"); } if(Flags & ~(X_D3DCLEAR_TARGET | X_D3DCLEAR_ZBUFFER | X_D3DCLEAR_STENCIL)) - EmuWarning("Unsupported Flag(s) for D3DDevice_Clear : 0x%.08X", Flags & ~(X_D3DCLEAR_TARGET | X_D3DCLEAR_ZBUFFER | X_D3DCLEAR_STENCIL)); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unsupported Flag(s) for D3DDevice_Clear : 0x%.08X", Flags & ~(X_D3DCLEAR_TARGET | X_D3DCLEAR_ZBUFFER | X_D3DCLEAR_STENCIL)); } DWORD dwFillMode; @@ -4580,7 +4580,7 @@ DWORD WINAPI XTL::EMUPATCH(D3DDevice_Swap) // TODO: Ensure this flag is always the same across library versions if (Flags != 0 && Flags != CXBX_SWAP_PRESENT_FORWARD) - EmuWarning("XTL::EmuD3DDevice_Swap: Flags != 0"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "XTL::EmuD3DDevice_Swap: Flags != 0"); // Fetch the host backbuffer XTL::IDirect3DSurface *pCurrentHostBackBuffer = nullptr; @@ -4619,7 +4619,7 @@ DWORD WINAPI XTL::EMUPATCH(D3DDevice_Swap) /* ColorKey = */ 0); if (hRet != D3D_OK) { - EmuWarning("Couldn't blit Xbox BackBuffer to host BackBuffer : %X", hRet); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Couldn't blit Xbox BackBuffer to host BackBuffer : %X", hRet); } } } @@ -4628,7 +4628,7 @@ DWORD WINAPI XTL::EMUPATCH(D3DDevice_Swap) if (g_OverlayProxy.Surface.Common) { X_D3DFORMAT X_Format = GetXboxPixelContainerFormat(&g_OverlayProxy.Surface); if (X_Format != X_D3DFMT_YUY2) { - LOG_TEST_CASE("Xbox overlay surface isn't using X_D3DFMT_YUY2"); + LOG_TEST_CASE(LOG_PREFIX, "Xbox overlay surface isn't using X_D3DFMT_YUY2"); } // Interpret the Xbox overlay data (depending the color space conversion render state) @@ -4694,7 +4694,7 @@ DWORD WINAPI XTL::EMUPATCH(D3DDevice_Swap) DEBUG_D3DRESULT(hRet, "D3DXLoadSurfaceFromMemory - UpdateOverlay could not convert buffer!\n"); if (hRet != D3D_OK) { - EmuWarning("Couldn't blit Xbox overlay to host BackBuffer : %X", hRet); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Couldn't blit Xbox overlay to host BackBuffer : %X", hRet); } } @@ -4797,7 +4797,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText case XTL::X_D3DRTYPE_PALETTE: ResourceTypeName = "Palette"; break; case XTL::X_D3DRTYPE_FIXUP: ResourceTypeName = "Fixup"; break; default: - EmuWarning("CreateHostResource :-> Unrecognized Xbox Resource Type 0x%.08X", XboxResourceType); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "CreateHostResource :-> Unrecognized Xbox Resource Type 0x%.08X", XboxResourceType); return; } @@ -4812,9 +4812,9 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText VAddr VirtualAddr = (VAddr)GetDataFromXboxResource(pResource); if ((VirtualAddr & ~PHYSICAL_MAP_BASE) == 0) { // TODO: Fix or handle this situation..? - LOG_TEST_CASE("CreateHostResource : VirtualAddr == 0"); + LOG_TEST_CASE(LOG_PREFIX, "CreateHostResource : VirtualAddr == 0"); // This is probably an unallocated resource, mapped into contiguous memory (0x80000000 OR 0xF0000000) - EmuWarning("CreateHostResource :-> %s carries no data - skipping conversion", ResourceTypeName); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "CreateHostResource :-> %s carries no data - skipping conversion", ResourceTypeName); return; } @@ -4847,7 +4847,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText DEBUG_D3DRESULT(hRet, "pHostParentTexture->GetSurfaceLevel"); if (hRet == D3D_OK) { SetHostSurface(pXboxSurface, pNewHostSurface); - DbgPrintf("CreateHostResource : Successfully created surface level (%u, 0x%.08X, 0x%.08X)\n", + DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created surface level (%u, 0x%.08X, 0x%.08X)\n", SurfaceLevel, pResource, pNewHostSurface); return; } @@ -4855,7 +4855,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText } } - EmuWarning("Failed getting host surface level - falling through to regular surface creation"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Failed getting host surface level - falling through to regular surface creation"); } // fall through } @@ -4872,12 +4872,12 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText DEBUG_D3DRESULT(hRet, "pParentHostVolumeTexture->GetVolumeLevel"); if (hRet == D3D_OK) { SetHostVolume(pXboxVolume, pNewHostVolume); - DbgPrintf("CreateHostResource : Successfully created volume level (%u, 0x%.08X, 0x%.08X)\n", + DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created volume level (%u, 0x%.08X, 0x%.08X)\n", VolumeLevel, pResource, pNewHostVolume); return; } - EmuWarning("Failed getting host volume level - falling through to regular volume creation"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Failed getting host volume level - falling through to regular volume creation"); } // fall through } @@ -4906,7 +4906,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText if (EmuXBFormatIsRenderTarget(X_Format)) D3DUsage |= D3DUSAGE_RENDERTARGET; else - EmuWarning("Updating RenderTarget %s with an incompatible format!", ResourceTypeName); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Updating RenderTarget %s with an incompatible format!", ResourceTypeName); } // Determine the format we'll be using on host D3D @@ -4982,21 +4982,21 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText // Otherwise, choose a fallback for the format not supported on host switch (X_Format) { case XTL::X_D3DFMT_LIN_D24S8: { // Note : This case could be removed, as the default below can handle it too - EmuWarning("D3DFMT_LIN_D24S8 %s not supported - using D3DFMT_A8R8G8B8!", ResourceTypeName); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "D3DFMT_LIN_D24S8 %s not supported - using D3DFMT_A8R8G8B8!", ResourceTypeName); // Note : This cannot set bConvertToARGB - we just copy it as-is PCFormat = XTL::D3DFMT_A8R8G8B8; break; } case XTL::X_D3DFMT_LIN_D16: { // Test case : Turok (when entering menu) - EmuWarning("D3DFMT_LIN_D16 %s not supported - USING D3DFMT_R5G6B5!", ResourceTypeName); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "D3DFMT_LIN_D16 %s not supported - USING D3DFMT_R5G6B5!", ResourceTypeName); // Note : This cannot set bConvertToARGB - we just copy it as-is PCFormat = XTL::D3DFMT_R5G6B5; // TODO : Do something smarter break; } case XTL::X_D3DFMT_X1R5G5B5: { // Note : This case could be removed, as the default below can handle it too // Test case : JSRF (after loading) - EmuWarning("D3DFMT_X1R5G5B5 %s will be converted to ARGB", ResourceTypeName); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "D3DFMT_X1R5G5B5 %s will be converted to ARGB", ResourceTypeName); bConvertToARGB = true; PCFormat = XTL::D3DFMT_A8R8G8B8; break; @@ -5004,13 +5004,13 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText default: // Can the format be converted to ARGB? if (EmuXBFormatCanBeConvertedToARGB(X_Format)) { - EmuWarning("Xbox %s Format %x will be converted to ARGB", ResourceTypeName, X_Format); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Xbox %s Format %x will be converted to ARGB", ResourceTypeName, X_Format); bConvertToARGB = true; PCFormat = XTL::D3DFMT_A8R8G8B8; } else { // Otherwise, use a best matching format - /*CxbxKrnlCleanup*/EmuWarning("Encountered a completely incompatible %s format!", ResourceTypeName); + /*CxbxKrnlCleanup*/EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Encountered a completely incompatible %s format!", ResourceTypeName); PCFormat = EmuXB2PC_D3DFormat(X_Format); } } @@ -5044,21 +5044,21 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText CxbxGetPixelContainerMeasures(pPixelContainer, 0, &dwWidth, &dwHeight, &dwDepth, &dwRowPitch, &dwSlicePitch); if (dwDepth != 1) { - LOG_TEST_CASE("CreateHostResource : Depth != 1"); + LOG_TEST_CASE(LOG_PREFIX, "CreateHostResource : Depth != 1"); } // The following is necessary for DXT* textures (4x4 blocks minimum) // TODO: Figure out if this is necessary under other circumstances? if (bCompressed) { if (dwWidth < dwMinSize) { - LOG_TEST_CASE("CreateHostResource : dwWidth < dwMinSize"); - EmuWarning("Expanding %s width (%d->%d)", ResourceTypeName, dwWidth, dwMinSize); + LOG_TEST_CASE(LOG_PREFIX, "CreateHostResource : dwWidth < dwMinSize"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Expanding %s width (%d->%d)", ResourceTypeName, dwWidth, dwMinSize); dwWidth = dwMinSize; } if (dwHeight < dwMinSize) { - LOG_TEST_CASE("CreateHostResource : dwHeight < dwMinSize"); - EmuWarning("Expanding %s height (%d->%d)", ResourceTypeName, dwHeight, dwMinSize); + LOG_TEST_CASE(LOG_PREFIX, "CreateHostResource : dwHeight < dwMinSize"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Expanding %s height (%d->%d)", ResourceTypeName, dwHeight, dwMinSize); dwHeight = dwMinSize; } } @@ -5104,29 +5104,29 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText // If this succeeds, the surface may not render correctly, but it won't crash if (hRet != D3D_OK) { if (D3DUsage & D3DUSAGE_DEPTHSTENCIL) { - EmuWarning("CreateDepthStencilSurface Failed\n\nError: %s\nDesc: %s", + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "CreateDepthStencilSurface Failed\n\nError: %s\nDesc: %s", XTL::DXGetErrorString(hRet), XTL::DXGetErrorDescription(hRet)); } else { - EmuWarning("CreateImageSurface Failed\n\nError: %s\nDesc: %s", + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "CreateImageSurface Failed\n\nError: %s\nDesc: %s", XTL::DXGetErrorString(hRet), XTL::DXGetErrorDescription(hRet)); } - EmuWarning("Trying Fallback"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Trying Fallback"); hRet = g_pD3DDevice->CreateOffscreenPlainSurface(dwWidth, dwHeight, PCFormat, D3DPool, &pNewHostSurface, nullptr); } // If the fallback failed, show an error and exit execution. if (hRet != D3D_OK) { // We cannot safely continue in this state. - CxbxKrnlCleanup("CreateImageSurface Failed!\n\nError: %s\nDesc: %s", + CxbxKrnlCleanup(LOG_PREFIX, "CreateImageSurface Failed!\n\nError: %s\nDesc: %s", XTL::DXGetErrorString(hRet), XTL::DXGetErrorDescription(hRet)); } SetHostSurface(pResource, pNewHostSurface); - DbgPrintf("CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n", + DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n", ResourceTypeName, pResource, pNewHostSurface); - DbgPrintf("CreateHostResource : Width : %d, Height : %d, Format : %d\n", + DbgPrintf(LOG_PREFIX, "CreateHostResource : Width : %d, Height : %d, Format : %d\n", dwWidth, dwHeight, PCFormat); break; } @@ -5139,7 +5139,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("CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n", + // DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n", // ResourceTypeName, pResource, pNewHostVolume); break; } @@ -5188,12 +5188,12 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText if (hRet != D3D_OK) { - CxbxKrnlCleanup("CreateTexture Failed!\n\n" + CxbxKrnlCleanup(LOG_PREFIX, "CreateTexture Failed!\n\n" "Error: 0x%X\nFormat: %d\nDimensions: %dx%d", hRet, PCFormat, dwWidth, dwHeight); } SetHostTexture(pResource, pNewHostTexture); - DbgPrintf("CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n", + DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n", ResourceTypeName, pResource, pNewHostTexture); break; } @@ -5206,18 +5206,18 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText DEBUG_D3DRESULT(hRet, "g_pD3DDevice->CreateVolumeTexture"); if (hRet != D3D_OK) { - CxbxKrnlCleanup("CreateVolumeTexture Failed!\n\nError: %s\nDesc: %s", + CxbxKrnlCleanup(LOG_PREFIX, "CreateVolumeTexture Failed!\n\nError: %s\nDesc: %s", XTL::DXGetErrorString(hRet), XTL::DXGetErrorDescription(hRet)); } SetHostVolumeTexture(pResource, pNewHostVolumeTexture); - DbgPrintf("CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n", + DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n", ResourceTypeName, pResource, pNewHostVolumeTexture); break; } case XTL::X_D3DRTYPE_CUBETEXTURE: { - DbgPrintf("CreateCubeTexture(%d, %d, 0, %d, D3DPOOL_MANAGED)\n", dwWidth, + DbgPrintf(LOG_PREFIX, "CreateCubeTexture(%d, %d, 0, %d, D3DPOOL_MANAGED)\n", dwWidth, dwMipMapLevels, PCFormat); hRet = g_pD3DDevice->CreateCubeTexture(dwWidth, dwMipMapLevels, D3DUsage, @@ -5227,7 +5227,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText DEBUG_D3DRESULT(hRet, "g_pD3DDevice->CreateCubeTexture"); if (hRet != D3D_OK) { - CxbxKrnlCleanup("CreateCubeTexture Failed!\n\nError: \nDesc: "/*, + CxbxKrnlCleanup(LOG_PREFIX, "CreateCubeTexture Failed!\n\nError: \nDesc: "/*, DXGetErrorString(hRet), DXGetErrorDescription(hRet)*/); } @@ -5235,7 +5235,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("CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n", + DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created %s (0x%.08X, 0x%.08X)\n", ResourceTypeName, pResource, pNewHostCubeTexture); break; } @@ -5295,7 +5295,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText } // switch XboxResourceType if (hRet != D3D_OK) { - EmuWarning("Locking host %s failed!", ResourceTypeName); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Locking host %s failed!", ResourceTypeName); continue; // This often happens on depth-stencil surfaces - let's ignore their copies for now } @@ -5321,7 +5321,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText // Do we need to convert to ARGB? if (bConvertToARGB) { - DbgPrintf("Unsupported texture format, expanding to D3DFMT_A8R8G8B8"); + DbgPrintf(LOG_PREFIX, "Unsupported texture format, expanding to D3DFMT_A8R8G8B8"); // Convert a row at a time, using a libyuv-like callback approach : if (!ConvertD3DTextureToARGBBuffer( @@ -5330,7 +5330,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText pDst, dwDstRowPitch, dwDstSlicePitch, dwDepth, iTextureStage)) { - CxbxKrnlCleanup("Unhandled conversion!"); + CxbxKrnlCleanup(LOG_PREFIX, "Unhandled conversion!"); } } else if (bSwizzled) { @@ -5394,7 +5394,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText } if (hRet != D3D_OK) { - EmuWarning("Unlocking host %s failed!", ResourceTypeName); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unlocking host %s failed!", ResourceTypeName); } if (face == XTL::D3DCUBEMAP_FACE_POSITIVE_X) { @@ -5483,12 +5483,12 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText dwSize = g_VMManager.QuerySize(VirtualAddr); if (dwSize == 0) { // TODO: once this is known to be working, remove the warning - EmuWarning("Push buffer allocation size unknown"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Push buffer allocation size unknown"); pPushBuffer->Lock = X_D3DRESOURCE_LOCK_FLAG_NOSIZE; break; } - DbgPrintf("CreateHostResource : Successfully created %S (0x%.08X, 0x%.08X, 0x%.08X)\n", ResourceTypeName, pResource->Data, pPushBuffer->Size, pPushBuffer->AllocationSize); + DbgPrintf(LOG_PREFIX, "CreateHostResource : Successfully created %S (0x%.08X, 0x%.08X, 0x%.08X)\n", ResourceTypeName, pResource->Data, pPushBuffer->Size, pPushBuffer->AllocationSize); break; } @@ -5497,7 +5497,7 @@ void CreateHostResource(XTL::X_D3DResource *pResource, DWORD D3DUsage, int iText case XTL::X_D3DRTYPE_FIXUP: { XTL::X_D3DFixup *pFixup = (XTL::X_D3DFixup*)pResource; - EmuWarning("X_D3DRTYPE_FIXUP is not yet supported\n" + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "X_D3DRTYPE_FIXUP is not yet supported\n" "0x%.08X (pFixup->Common) \n" "0x%.08X (pFixup->Data) \n" "0x%.08X (pFixup->Lock) \n" @@ -5702,7 +5702,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetTextureState_TexCoordIndex_4) // Check for 0x00040000 instead. if (Value >= 0x00040000) { - EmuWarning("EmuD3DDevice_SetTextureState_TexCoordIndex: Unknown TexCoordIndex Value (0x%.08X)", Value); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuD3DDevice_SetTextureState_TexCoordIndex: Unknown TexCoordIndex Value (0x%.08X)", Value); return; } @@ -5732,7 +5732,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetTextureState_TexCoordIndex) // Check for 0x00040000 instead. if (Value >= 0x00040000) { - EmuWarning("EmuD3DDevice_SetTextureState_TexCoordIndex: Unknown TexCoordIndex Value (0x%.08X)", Value); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuD3DDevice_SetTextureState_TexCoordIndex: Unknown TexCoordIndex Value (0x%.08X)", Value); return; } @@ -5816,7 +5816,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetTextureState_BorderColor_4) // LOG_FUNC_ARG(Stage) // LOG_FUNC_ARG(Value) // LOG_FUNC_END; - DbgPrintf("D3DDevice_SetTextureState_BorderColor_4(Stage : %d Value : %d);\n", Stage, Value); + DbgPrintf(LOG_PREFIX, "D3DDevice_SetTextureState_BorderColor_4(Stage : %d Value : %d);\n", Stage, Value); HRESULT hRet; hRet = g_pD3DDevice->SetSamplerState(Stage, D3DSAMP_BORDERCOLOR, Value); @@ -5918,7 +5918,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetTextureState_BumpEnv_8) // LOG_FUNC_ARG(Type) // LOG_FUNC_ARG(Value) // LOG_FUNC_END; - DbgPrintf("D3DDevice_SetTextureState_BumpEnv_8(Stage : %d Type : %d Value : %d);\n", Stage, Type, Value); + DbgPrintf(LOG_PREFIX, "D3DDevice_SetTextureState_BumpEnv_8(Stage : %d Type : %d Value : %d);\n", Stage, Type, Value); HRESULT hRet = D3D_OK; @@ -6249,7 +6249,7 @@ VOID __fastcall XTL::EMUPATCH(D3DDevice_SetRenderState_Simple) } } - EmuWarning("RenderState_Simple(0x%.08X (%s), 0x%.08X) is unsupported!", Method, name.c_str(), Value); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "RenderState_Simple(0x%.08X (%s), 0x%.08X) is unsupported!", Method, name.c_str(), Value); } else { @@ -6270,89 +6270,89 @@ VOID __fastcall XTL::EMUPATCH(D3DDevice_SetRenderState_Simple) if(OrigValue & (1L<<24)) Value |= D3DCOLORWRITEENABLE_ALPHA; - DbgPrintf("D3DRS_COLORWRITEENABLE := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_COLORWRITEENABLE := 0x%.08X\n", Value); } break; case D3DRS_SHADEMODE: Value = EmuXB2PC_D3DSHADEMODE(Value); - DbgPrintf("D3DRS_SHADEMODE := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_SHADEMODE := 0x%.08X\n", Value); break; case D3DRS_BLENDOP: Value = EmuXB2PC_D3DBLENDOP(Value); - DbgPrintf("D3DRS_BLENDOP := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_BLENDOP := 0x%.08X\n", Value); break; case D3DRS_SRCBLEND: Value = EmuXB2PC_D3DBLEND(Value); - DbgPrintf("D3DRS_SRCBLEND := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_SRCBLEND := 0x%.08X\n", Value); break; case D3DRS_DESTBLEND: Value = EmuXB2PC_D3DBLEND(Value); - DbgPrintf("D3DRS_DESTBLEND := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_DESTBLEND := 0x%.08X\n", Value); break; case D3DRS_ZFUNC: Value = EmuXB2PC_D3DCMPFUNC(Value); - DbgPrintf("D3DRS_ZFUNC := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_ZFUNC := 0x%.08X\n", Value); break; case D3DRS_ALPHAFUNC: Value = EmuXB2PC_D3DCMPFUNC(Value); - DbgPrintf("D3DRS_ALPHAFUNC := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_ALPHAFUNC := 0x%.08X\n", Value); break; case D3DRS_ALPHATESTENABLE: - DbgPrintf("D3DRS_ALPHATESTENABLE := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_ALPHATESTENABLE := 0x%.08X\n", Value); break; case D3DRS_ALPHABLENDENABLE: - DbgPrintf("D3DRS_ALPHABLENDENABLE := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_ALPHABLENDENABLE := 0x%.08X\n", Value); break; case D3DRS_ALPHAREF: - DbgPrintf("D3DRS_ALPHAREF := %lf\n", DWtoF(Value)); + DbgPrintf(LOG_PREFIX, "D3DRS_ALPHAREF := %lf\n", DWtoF(Value)); break; case D3DRS_ZWRITEENABLE: - DbgPrintf("D3DRS_ZWRITEENABLE := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_ZWRITEENABLE := 0x%.08X\n", Value); break; case D3DRS_DITHERENABLE: - DbgPrintf("D3DRS_DITHERENABLE := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_DITHERENABLE := 0x%.08X\n", Value); break; case D3DRS_STENCILZFAIL: Value = EmuXB2PC_D3DSTENCILOP(Value); - DbgPrintf("D3DRS_STENCILZFAIL := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_STENCILZFAIL := 0x%.08X\n", Value); break; case D3DRS_STENCILPASS: Value = EmuXB2PC_D3DSTENCILOP(Value); - DbgPrintf("D3DRS_STENCILPASS := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_STENCILPASS := 0x%.08X\n", Value); break; case D3DRS_STENCILFUNC: Value = EmuXB2PC_D3DCMPFUNC(Value); - DbgPrintf("D3DRS_STENCILFUNC := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_STENCILFUNC := 0x%.08X\n", Value); break; case D3DRS_STENCILREF: - DbgPrintf("D3DRS_STENCILREF := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_STENCILREF := 0x%.08X\n", Value); break; case D3DRS_STENCILMASK: - DbgPrintf("D3DRS_STENCILMASK := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_STENCILMASK := 0x%.08X\n", Value); break; case D3DRS_STENCILWRITEMASK: - DbgPrintf("D3DRS_STENCILWRITEMASK := 0x%.08X\n", Value); + DbgPrintf(LOG_PREFIX, "D3DRS_STENCILWRITEMASK := 0x%.08X\n", Value); break; default: - CxbxKrnlCleanup("Unsupported RenderState (0x%.08X)", State); + CxbxKrnlCleanup(LOG_PREFIX, "Unsupported RenderState (0x%.08X)", State); break; }; @@ -6382,7 +6382,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetRenderState_VertexBlend) } else if(Value == 5) { Value = 3; } else { - LOG_TEST_CASE("Unsupported D3DVERTEXBLENDFLAGS (%d)", Value); + LOG_TEST_CASE(LOG_PREFIX, "Unsupported D3DVERTEXBLENDFLAGS (%d)", Value); return; } @@ -6430,7 +6430,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetRenderState_CullMode) Value = D3DCULL_CCW; break; default: - CxbxKrnlCleanup("EmuD3DDevice_SetRenderState_CullMode: Unknown Cullmode (%d)", Value); + CxbxKrnlCleanup(LOG_PREFIX, "EmuD3DDevice_SetRenderState_CullMode: Unknown Cullmode (%d)", Value); } HRESULT hRet = g_pD3DDevice->SetRenderState(D3DRS_CULLMODE, Value); @@ -6882,7 +6882,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetStreamSource_4) // LOG_FUNC_ARG(pStreamData) // LOG_FUNC_ARG(Stride) // LOG_FUNC_END; - DbgPrintf("D3DDevice_SetStreamSource_4(StreamNumber : %08X pStreamData : %08X Stride : %08X);\n", StreamNumber, pStreamData, Stride); + DbgPrintf(LOG_PREFIX, "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! @@ -6917,7 +6917,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetStreamSource_8) // LOG_FUNC_ARG(pStreamData) // LOG_FUNC_ARG(Stride) // LOG_FUNC_END; - DbgPrintf("D3DDevice_SetStreamSource_8(StreamNumber : %08X pStreamData : %08X Stride : %08X);\n", StreamNumber, pStreamData, Stride); + DbgPrintf(LOG_PREFIX, "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! @@ -7107,7 +7107,7 @@ void CxbxAssureQuadListD3DIndexBuffer(UINT NrOfQuadVertices) DEBUG_D3DRESULT(hRet, "g_pD3DDevice->CreateIndexBuffer"); if (FAILED(hRet)) - CxbxKrnlCleanup("CxbxAssureQuadListD3DIndexBuffer : IndexBuffer Create Failed!"); + CxbxKrnlCleanup(LOG_PREFIX, "CxbxAssureQuadListD3DIndexBuffer : IndexBuffer Create Failed!"); // Put quadlist-to-triangle-list index mappings into this buffer : XTL::INDEX16* pIndexBufferData = nullptr; @@ -7115,7 +7115,7 @@ void CxbxAssureQuadListD3DIndexBuffer(UINT NrOfQuadVertices) DEBUG_D3DRESULT(hRet, "pQuadToTriangleD3DIndexBuffer->Lock"); if (pIndexBufferData == nullptr) - CxbxKrnlCleanup("CxbxAssureQuadListD3DIndexBuffer : Could not lock index buffer!"); + CxbxKrnlCleanup(LOG_PREFIX, "CxbxAssureQuadListD3DIndexBuffer : Could not lock index buffer!"); memcpy(pIndexBufferData, CxbxAssureQuadListIndexBuffer(NrOfQuadVertices), uiIndexBufferSize); @@ -7127,7 +7127,7 @@ void CxbxAssureQuadListD3DIndexBuffer(UINT NrOfQuadVertices) DEBUG_D3DRESULT(hRet, "g_pD3DDevice->SetIndices"); if (FAILED(hRet)) - CxbxKrnlCleanup("CxbxAssureQuadListD3DIndexBuffer : SetIndices Failed!"); // +DxbxD3DErrorString(hRet)); + CxbxKrnlCleanup(LOG_PREFIX, "CxbxAssureQuadListD3DIndexBuffer : SetIndices Failed!"); // +DxbxD3DErrorString(hRet)); } // TODO : Move to own file @@ -7149,7 +7149,7 @@ void CxbxDrawIndexedClosingLine(XTL::INDEX16 LowIndex, XTL::INDEX16 HighIndex) nullptr // pSharedHandle ); if (FAILED(hRet)) - CxbxKrnlCleanup("Unable to create pClosingLineLoopIndexBuffer for D3DPT_LINELOOP emulation"); + CxbxKrnlCleanup(LOG_PREFIX, "Unable to create pClosingLineLoopIndexBuffer for D3DPT_LINELOOP emulation"); } XTL::INDEX16 *pCxbxClosingLineLoopIndexBufferData = nullptr; @@ -7283,7 +7283,7 @@ void XTL::CxbxDrawIndexed(CxbxDrawContext &DrawContext) g_dwPrimPerFrame += DrawContext.dwHostPrimitiveCount; if (DrawContext.XboxPrimitiveType == X_D3DPT_LINELOOP) { // Close line-loops using a final single line, drawn from the end to the start vertex - LOG_TEST_CASE("X_D3DPT_LINELOOP"); + LOG_TEST_CASE(LOG_PREFIX, "X_D3DPT_LINELOOP"); // Read the end and start index from the supplied index data LowIndex = DrawContext.pIndexData[0]; HighIndex = DrawContext.pIndexData[DrawContext.dwHostPrimitiveCount]; @@ -7316,7 +7316,7 @@ void XTL::CxbxDrawPrimitiveUP(CxbxDrawContext &DrawContext) CxbxVertexBufferConverter VertexBufferConverter = {}; VertexBufferConverter.Apply(&DrawContext); if (DrawContext.XboxPrimitiveType == X_D3DPT_QUADLIST) { - // LOG_TEST_CASE("X_D3DPT_QUADLIST"); // X-Marbles and XDK Sample PlayField hits this case + // LOG_TEST_CASE(LOG_PREFIX, "X_D3DPT_QUADLIST"); // X-Marbles and XDK Sample PlayField hits this case // Draw quadlists using a single 'quad-to-triangle mapping' index buffer : INDEX16 *pIndexData = CxbxAssureQuadListIndexBuffer(DrawContext.dwVertexCount); // Convert quad vertex-count to triangle vertex count : @@ -7439,7 +7439,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetPixelShader_0) //LOG_FUNC_ONE_ARG(LOG_PREFIX, Handle); - DbgPrintf("D3DDevice_SetPixelShader_0(Handle : %d);\n", Handle); + DbgPrintf(LOG_PREFIX, "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, ()); @@ -7488,7 +7488,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DrawVertices) // Dxbx Note : In DrawVertices and DrawIndexedVertices, PrimitiveType may not be D3DPT_POLYGON if (!EmuD3DValidVertexCount(PrimitiveType, VertexCount)) { - LOG_TEST_CASE("Invalid VertexCount"); + LOG_TEST_CASE(LOG_PREFIX, "Invalid VertexCount"); return; } @@ -7505,9 +7505,9 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DrawVertices) CxbxVertexBufferConverter VertexBufferConverter = {}; VertexBufferConverter.Apply(&DrawContext); if (DrawContext.XboxPrimitiveType == X_D3DPT_QUADLIST) { - // LOG_TEST_CASE("X_D3DPT_QUADLIST"); // ?X-Marbles and XDK Sample (Cartoon, ?maybe PlayField?) hits this case + // LOG_TEST_CASE(LOG_PREFIX, "X_D3DPT_QUADLIST"); // ?X-Marbles and XDK Sample (Cartoon, ?maybe PlayField?) hits this case if (StartVertex > 0) { - LOG_TEST_CASE("X_D3DPT_QUADLIST StartVertex > 0"); + LOG_TEST_CASE(LOG_PREFIX, "X_D3DPT_QUADLIST StartVertex > 0"); // test-case : BLiNX: the time sweeper // test-case : Halo - Combat Evolved // test-case : Worms 3D Special Edition @@ -7538,7 +7538,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DrawVertices) g_dwPrimPerFrame += primCount; } else { - // if (StartVertex > 0) LOG_TEST_CASE("StartVertex > 0 (non-quad)"); // Verified test case : XDK Sample (PlayField) + // if (StartVertex > 0) LOG_TEST_CASE(LOG_PREFIX, "StartVertex > 0 (non-quad)"); // Verified test case : XDK Sample (PlayField) HRESULT hRet = g_pD3DDevice->DrawPrimitive( EmuXB2PC_D3DPrimitiveType(DrawContext.XboxPrimitiveType), DrawContext.dwStartVertex, @@ -7549,7 +7549,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DrawVertices) g_dwPrimPerFrame += DrawContext.dwHostPrimitiveCount; if (DrawContext.XboxPrimitiveType == X_D3DPT_LINELOOP) { // Close line-loops using a final single line, drawn from the end to the start vertex - LOG_TEST_CASE("X_D3DPT_LINELOOP"); // TODO : Text-cases needed + LOG_TEST_CASE(LOG_PREFIX, "X_D3DPT_LINELOOP"); // TODO : Text-cases needed INDEX16 LowIndex = (INDEX16)DrawContext.dwStartVertex; INDEX16 HighIndex = (INDEX16)(DrawContext.dwStartVertex + DrawContext.dwHostPrimitiveCount); // Draw the closing line using a helper function (which will SetIndices) @@ -7589,7 +7589,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DrawVerticesUP) LOG_FUNC_END; if (!EmuD3DValidVertexCount(PrimitiveType, VertexCount)) { - LOG_TEST_CASE("Invalid VertexCount"); + LOG_TEST_CASE(LOG_PREFIX, "Invalid VertexCount"); return; } @@ -7641,7 +7641,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DrawIndexedVertices) LOG_FUNC_END; if (!EmuD3DValidVertexCount(PrimitiveType, VertexCount)) { - LOG_TEST_CASE("Invalid VertexCount"); + LOG_TEST_CASE(LOG_PREFIX, "Invalid VertexCount"); return; } @@ -7699,7 +7699,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DrawIndexedVerticesUP) LOG_FUNC_END; if (!EmuD3DValidVertexCount(PrimitiveType, VertexCount)) { - LOG_TEST_CASE("Invalid VertexCount"); + LOG_TEST_CASE(LOG_PREFIX, "Invalid VertexCount"); return; } @@ -7726,7 +7726,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DrawIndexedVerticesUP) // This is slower (because of call-overhead) but doesn't require any index buffer patching // Draw 1 quad as a 2 triangles in a fan (which both have the same winding order) : - // LOG_TEST_CASE("X_D3DPT_QUADLIST"); // Test-case : Buffy: The Vampire Slayer, FastLoad XDK Sample + // LOG_TEST_CASE(LOG_PREFIX, "X_D3DPT_QUADLIST"); // Test-case : Buffy: The Vampire Slayer, FastLoad XDK Sample INDEX16* pWalkIndexData = (INDEX16*)pIndexData; int iNumVertices = (int)VertexCount; while (iNumVertices >= VERTICES_PER_QUAD) { @@ -7758,7 +7758,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DrawIndexedVerticesUP) INDEX16 LowIndex, HighIndex; WalkIndexBuffer(LowIndex, HighIndex, (INDEX16*)pIndexData, DrawContext.dwVertexCount); - // LOG_TEST_CASE("DrawIndexedPrimitiveUP"); // Test-case : Burnout, Namco Museum 50th Anniversary + // LOG_TEST_CASE(LOG_PREFIX, "DrawIndexedPrimitiveUP"); // Test-case : Burnout, Namco Museum 50th Anniversary HRESULT hRet = g_pD3DDevice->DrawIndexedPrimitiveUP( EmuXB2PC_D3DPrimitiveType(DrawContext.XboxPrimitiveType), LowIndex, // MinVertexIndex @@ -7774,7 +7774,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DrawIndexedVerticesUP) g_dwPrimPerFrame += DrawContext.dwHostPrimitiveCount; if (DrawContext.XboxPrimitiveType == X_D3DPT_LINELOOP) { // Close line-loops using a final single line, drawn from the end to the start vertex - LOG_TEST_CASE("X_D3DPT_LINELOOP"); // TODO : Which titles reach this case? + LOG_TEST_CASE(LOG_PREFIX, "X_D3DPT_LINELOOP"); // TODO : Which titles reach this case? // Read the end and start index from the supplied index data LowIndex = ((INDEX16*)pIndexData)[0]; HighIndex = ((INDEX16*)pIndexData)[DrawContext.dwHostPrimitiveCount]; @@ -8014,7 +8014,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetRenderTarget) pRenderTarget = g_pXboxRenderTarget; // If there's no Xbox render target yet, fallback to the Xbox back buffer if (pRenderTarget == xbnullptr) { - LOG_TEST_CASE("SetRenderTarget fallback to backbuffer"); + LOG_TEST_CASE(LOG_PREFIX, "SetRenderTarget fallback to backbuffer"); pRenderTarget = g_XboxBackBufferSurface; } } @@ -8032,7 +8032,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetRenderTarget) DEBUG_D3DRESULT(hRet, "g_pD3DDevice->GetBackBuffer"); if (FAILED(hRet)) { - CxbxKrnlCleanup("Could not get host backbuffer"); + CxbxKrnlCleanup(LOG_PREFIX, "Could not get host backbuffer"); } } @@ -8261,7 +8261,7 @@ VOID __stdcall XTL::EMUPATCH(D3DDevice_DeleteVertexShader_0) mov Handle, eax } - LOG_TEST_CASE("Validate this function!"); + LOG_TEST_CASE(LOG_PREFIX, "Validate this function!"); return EMUPATCH(D3DDevice_DeleteVertexShader)(Handle); } @@ -8536,7 +8536,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_LoadVertexShaderProgram) { DWORD hNewShader = 0; - // Save the contents of the existing vertex shader program + // Save the contents of the existing vertex shader programLOG_TEST_CASE(LOG_PREFIX, DWORD* pDeclaration = (DWORD*) malloc( pVertexShader->DeclarationSize ); memmove( pDeclaration, pVertexShader->pDeclaration, pVertexShader->DeclarationSize ); @@ -8544,14 +8544,14 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_LoadVertexShaderProgram) HRESULT hr = EMUPATCH(D3DDevice_CreateVertexShader)( pDeclaration, pFunction, &hNewShader, 0 ); free(pDeclaration); if( FAILED( hr ) ) - CxbxKrnlCleanup( "Error creating new vertex shader!" ); + CxbxKrnlCleanup(LOG_PREFIX, "Error creating new vertex shader!" ); EMUPATCH(D3DDevice_LoadVertexShader)(hNewShader, Address); EMUPATCH(D3DDevice_SelectVertexShader)(hNewShader, Address); g_LoadVertexShaderProgramCache[shaderCacheKey] = hNewShader; - EmuWarning("Vertex Shader Cache Size: %d", g_LoadVertexShaderProgramCache.size()); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Vertex Shader Cache Size: %d", g_LoadVertexShaderProgramCache.size()); } } @@ -8736,7 +8736,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_SetDepthClipPlanes) break; default: - EmuWarning("Unknown SetDepthClipPlanes Flags provided");; + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unknown SetDepthClipPlanes Flags provided");; } // TODO @@ -8829,7 +8829,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetScreenSpaceOffset) LOG_FUNC_ARG(y) LOG_FUNC_END; - EmuWarning("EmuD3DDevice_SetScreenSpaceOffset ignored"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuD3DDevice_SetScreenSpaceOffset ignored"); } // ****************************************************************** @@ -9263,7 +9263,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_GetMaterial) if(FAILED(hRet)) { - EmuWarning("We're lying about getting a material!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "We're lying about getting a material!"); hRet = D3D_OK; } } @@ -9292,7 +9292,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetPixelShaderConstant_4) // LOG_FUNC_ARG(pConstantData) // LOG_FUNC_ARG(ConstantCount) // LOG_FUNC_END; - DbgPrintf("D3DDevice_SetPixelShaderConstant_4(Register : %d pConstantData : %08X ConstantCount : %d);\n", Register, pConstantData, ConstantCount); + DbgPrintf(LOG_PREFIX, "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. @@ -9309,7 +9309,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetPixelShaderConstant_4) if(FAILED(hRet)) { - EmuWarning("We're lying about setting a pixel shader constant!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "We're lying about setting a pixel shader constant!"); hRet = D3D_OK; } diff --git a/src/CxbxKrnl/EmuD3D8/Convert.cpp b/src/CxbxKrnl/EmuD3D8/Convert.cpp index 6fd5c407e..cc701a14f 100755 --- a/src/CxbxKrnl/EmuD3D8/Convert.cpp +++ b/src/CxbxKrnl/EmuD3D8/Convert.cpp @@ -1037,7 +1037,7 @@ XTL::D3DFORMAT XTL::EmuXB2PC_D3DFormat(X_D3DFORMAT Format) { const FormatInfo *info = &FormatInfos[Format]; if (info->warning != nullptr) { - DbgPrintf("EmuXB2PC_D3DFormat %s\n", info->warning); + DbgPrintf(LOG_PREFIX_D3DCVT, "EmuXB2PC_D3DFormat %s\n", info->warning); } return info->pc; @@ -1049,7 +1049,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("EmuXB2PC_D3DFormat: Unknown Format (0x%.08X)", Format); + CxbxKrnlCleanup(LOG_PREFIX_D3DCVT, "EmuXB2PC_D3DFormat: Unknown Format (0x%.08X)", Format); } return D3DFMT_UNKNOWN; @@ -1131,7 +1131,7 @@ XTL::X_D3DFORMAT XTL::EmuPC2XB_D3DFormat(D3DFORMAT Format, bool bPreferLinear) result = X_D3DFMT_VERTEXDATA; break; default: - CxbxKrnlCleanup("EmuPC2XB_D3DFormat: Unknown Format (%d)", Format); + CxbxKrnlCleanup(LOG_PREFIX_D3DCVT, "EmuPC2XB_D3DFormat: Unknown Format (%d)", Format); } return result; @@ -1183,7 +1183,7 @@ XTL::D3DMULTISAMPLE_TYPE XTL::EmuXB2PC_D3DMultiSampleFormat(DWORD Type) result = D3DMULTISAMPLE_9_SAMPLES; break; default: - EmuWarning("Unknown Multisample Type (0x%X)!\x0d\x0a.", Type); + EmuLog(LOG_PREFIX_D3DCVT, LOG_LEVEL::WARNING, "Unknown Multisample Type (0x%X)!\x0d\x0a.", Type); result = D3DMULTISAMPLE_NONE; } return result; diff --git a/src/CxbxKrnl/EmuD3D8/Convert.h b/src/CxbxKrnl/EmuD3D8/Convert.h index 8ce72b2d4..36b26f306 100755 --- a/src/CxbxKrnl/EmuD3D8/Convert.h +++ b/src/CxbxKrnl/EmuD3D8/Convert.h @@ -38,7 +38,9 @@ #define VERTICES_PER_TRIANGLE 3 #define VERTICES_PER_QUAD 4 -#define TRIANGLES_PER_QUAD 2 +#define TRIANGLES_PER_QUAD 2 + +#define LOG_PREFIX_D3DCVT CXBXR_MODULE::D3DCVT // simple render state encoding lookup table #define X_D3DRSSE_UNK 0x7fffffff @@ -94,7 +96,7 @@ else if((uint32)State < 20) else if((uint32)State > 255) State = (D3DTRANSFORMSTATETYPE)(State - 250); else - CxbxKrnlCleanup("Unknown Transform State Type (%d)", State); + CxbxKrnlCleanup(LOG_PREFIX_D3DCVT, "Unknown Transform State Type (%d)", State); //*/ // convert from xbox to pc texture transform state types @@ -109,7 +111,7 @@ inline D3DTRANSFORMSTATETYPE EmuXB2PC_D3DTS(D3DTRANSFORMSTATETYPE State) else if((uint32)State == 10) // Max return (D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE7 + 1); - CxbxKrnlCleanup("Unknown Transform State Type (%d)", State); + CxbxKrnlCleanup(LOG_PREFIX_D3DCVT, "Unknown Transform State Type (%d)", State); return State; } @@ -131,17 +133,17 @@ inline D3DBLENDOP EmuXB2PC_D3DBLENDOP(X_D3DBLENDOP Value) return D3DBLENDOP_MAX; case 0xF006: { - EmuWarning("D3DBLENDOP_ADDSIGNED is not supported!"); + EmuLog(LOG_PREFIX_D3DCVT, LOG_LEVEL::WARNING, "D3DBLENDOP_ADDSIGNED is not supported!"); return D3DBLENDOP_ADD; }; case 0xF005: { - EmuWarning("D3DBLENDOP_REVSUBTRACTSIGNED is not supported!"); + EmuLog(LOG_PREFIX_D3DCVT, LOG_LEVEL::WARNING, "D3DBLENDOP_REVSUBTRACTSIGNED is not supported!"); return D3DBLENDOP_REVSUBTRACT; } } - EmuWarning("Unknown D3DBLENDOP (0x%.08X)", Value); + EmuLog(LOG_PREFIX_D3DCVT, LOG_LEVEL::WARNING, "Unknown D3DBLENDOP (0x%.08X)", Value); return (D3DBLENDOP)D3DBLENDOP_ADD; } @@ -154,7 +156,7 @@ inline D3DBLEND EmuXB2PC_D3DBLEND(X_D3DBLEND Value) else if(Value < 0x309) return (D3DBLEND)((Value & 0xF) + 3); - EmuWarning("Unknown Xbox D3DBLEND Extension (0x%.08X)", Value); + EmuLog(LOG_PREFIX_D3DCVT, LOG_LEVEL::WARNING, "Unknown Xbox D3DBLEND Extension (0x%.08X)", Value); return D3DBLEND_ONE; } @@ -199,7 +201,7 @@ inline D3DSTENCILOP EmuXB2PC_D3DSTENCILOP(X_D3DSTENCILOP Value) return D3DSTENCILOP_DECR; default: - CxbxKrnlCleanup("Unknown D3DSTENCILOP (0x%.08X)", Value); + CxbxKrnlCleanup(LOG_PREFIX_D3DCVT, "Unknown D3DSTENCILOP (0x%.08X)", Value); } return (D3DSTENCILOP) Value; diff --git a/src/CxbxKrnl/EmuD3D8/PixelShader.cpp b/src/CxbxKrnl/EmuD3D8/PixelShader.cpp index 578395817..5903a884f 100644 --- a/src/CxbxKrnl/EmuD3D8/PixelShader.cpp +++ b/src/CxbxKrnl/EmuD3D8/PixelShader.cpp @@ -71,6 +71,8 @@ // #include //}; +#define LOG_PREFIX CXBXR_MODULE::PXSH + #include "CxbxKrnl/Emu.h" #include "CxbxKrnl/EmuFS.h" #include "CxbxKrnl/EmuXTL.h" @@ -1381,7 +1383,7 @@ bool PSH_IMD_ARGUMENT::Decode(const DWORD Value, DWORD aMask, TArgumentType Argu Type = PARAM_EF_PROD; break; default : - DbgPrintf("INVALID ARGUMENT!\n"); + DbgPrintf(LOG_PREFIX, "INVALID ARGUMENT!\n"); Result = false; } @@ -1972,8 +1974,8 @@ void PSH_XBOX_SHADER::Log(const char *PhaseStr) { //if (MayLog(lfUnit)) { - DbgPrintf("New decoding - %s :\n", PhaseStr); - DbgPrintf("%s\n", ToString().c_str()); + DbgPrintf(LOG_PREFIX, "New decoding - %s :\n", PhaseStr); + DbgPrintf(LOG_PREFIX, "%s\n", ToString().c_str()); } } @@ -2153,7 +2155,7 @@ PSH_RECOMPILED_SHADER PSH_XBOX_SHADER::Decode(XTL::X_D3DPIXELSHADERDEF *pPSDef) //if (MayLog(LogFlags)) { // print relevant contents to the debug console - DbgPrintf("%s\n", DecodedToString(pPSDef).c_str()); + DbgPrintf(LOG_PREFIX, "%s\n", DecodedToString(pPSDef).c_str()); } // TODO: @@ -2550,7 +2552,7 @@ bool PSH_XBOX_SHADER::MoveRemovableParametersRight() if (Result >= MaxConstantFloatRegisters) Result = 0; - EmuWarning("; Too many constants to emulate, this pixel shader will give unexpected output!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "; Too many constants to emulate, this pixel shader will give unexpected output!"); return Result; } @@ -2730,7 +2732,7 @@ bool PSH_XBOX_SHADER::RemoveUselessWrites() if ( (CurArg->Address < MaxTemporaryRegisters) && ((RegUsage[CurArg->Type][CurArg->Address] & CurArg->Mask) == 0)) { - DbgPrintf("; Removed useless assignment to register %s\n", CurArg->ToString().c_str()); + DbgPrintf(LOG_PREFIX, "; Removed useless assignment to register %s\n", CurArg->ToString().c_str()); CurArg->Type = PARAM_DISCARD; Result = true; } @@ -3027,7 +3029,7 @@ void PSH_XBOX_SHADER::ConvertXFCToNative(int i) InsertIntermediate(&Ins, InsertPos); ++InsertPos; - DbgPrintf("; Inserted final combiner calculation of V1R0_sum register\n"); + DbgPrintf(LOG_PREFIX, "; Inserted final combiner calculation of V1R0_sum register\n"); } if (NeedsProd) @@ -3039,7 +3041,7 @@ void PSH_XBOX_SHADER::ConvertXFCToNative(int i) Ins.Parameters[1] = Cur.Parameters[5]; // F InsertIntermediate(&Ins, InsertPos); ++InsertPos; - DbgPrintf("; Inserted final combiner calculation of EF_prod register\n"); + DbgPrintf(LOG_PREFIX, "; Inserted final combiner calculation of EF_prod register\n"); } // The final combiner calculates : r0.rgb=s0*s1 + (1-s0)*s2 + s3 @@ -3202,7 +3204,7 @@ bool PSH_XBOX_SHADER::FixConstantModifiers() Ins.Parameters[0].Modifiers = 0; Ins.CommentString = "Inserted to avoid constant modifier (applied below on register)"; InsertIntermediate(&Ins, i); - DbgPrintf("; Used intermediate move to avoid constant modifier\n"); + DbgPrintf(LOG_PREFIX, "; Used intermediate move to avoid constant modifier\n"); Result = true; } } @@ -3290,7 +3292,7 @@ bool PSH_XBOX_SHADER::CombineInstructions() Op2->Parameters[2] = Op1->Parameters[0]; DeleteIntermediate(i); DeleteIntermediate(i); - DbgPrintf("; Changed temporary MUL,MUL,CND via MOV,MOV,CND into a single CND\n"); + DbgPrintf(LOG_PREFIX, "; Changed temporary MUL,MUL,CND via MOV,MOV,CND into a single CND\n"); Result = true; continue; } @@ -3315,7 +3317,7 @@ bool PSH_XBOX_SHADER::CombineInstructions() Op2->Modifier = Op0->Modifier; DeleteIntermediate(i); DeleteIntermediate(i); - DbgPrintf("; Changed temporary MUL,MUL,ADD into a single LRP\n"); + DbgPrintf(LOG_PREFIX, "; Changed temporary MUL,MUL,ADD into a single LRP\n"); Result = true; continue; } @@ -3332,7 +3334,7 @@ bool PSH_XBOX_SHADER::CombineInstructions() Op2->Modifier = Op0->Modifier; DeleteIntermediate(i); DeleteIntermediate(i); - DbgPrintf("; Changed temporary MUL,MUL,ADD into a single MAD\n"); + DbgPrintf(LOG_PREFIX, "; Changed temporary MUL,MUL,ADD into a single MAD\n"); Result = true; continue; } @@ -3347,7 +3349,7 @@ bool PSH_XBOX_SHADER::CombineInstructions() Op1->Parameters[2] = Op0->Output[0]; // Remove the trailing ADD : DeleteIntermediate(i+2); - DbgPrintf("; Changed temporary MUL,MUL,ADD into a MUL,MAD\n"); + DbgPrintf(LOG_PREFIX, "; Changed temporary MUL,MUL,ADD into a MUL,MAD\n"); Result = true; continue; } @@ -3364,7 +3366,7 @@ bool PSH_XBOX_SHADER::CombineInstructions() Op2->Parameters[1] = Op1->Parameters[0]; DeleteIntermediate(i); DeleteIntermediate(i); - DbgPrintf("; Changed temporary MUL,MUL,ADD into a MUL\n"); + DbgPrintf(LOG_PREFIX, "; Changed temporary MUL,MUL,ADD into a MUL\n"); Result = true; continue; } @@ -3389,7 +3391,7 @@ bool PSH_XBOX_SHADER::CombineInstructions() Op0->Opcode = PO_MAD; Op0->Parameters[2] = Op1->Parameters[1]; DeleteIntermediate(i+1); - DbgPrintf("; Changed MUL,ADD into a single MAD\n"); + DbgPrintf(LOG_PREFIX, "; Changed MUL,ADD into a single MAD\n"); Result = true; continue; } @@ -3474,7 +3476,7 @@ bool PSH_XBOX_SHADER::CombineInstructions() if (CanOptimize) { DeleteIntermediate(i); - DbgPrintf("; Moved MOV input into following instructions\n3"); + DbgPrintf(LOG_PREFIX, "; Moved MOV input into following instructions\n3"); Result = true; } } @@ -3494,7 +3496,7 @@ bool PSH_XBOX_SHADER::CombineInstructions() // > mul r0.rgb, r0,t0 Op0->Output[0] = Op1->Output[0]; DeleteIntermediate(i+1); - DbgPrintf("; Changed temporary MUL,MOV into a MUL\n"); + DbgPrintf(LOG_PREFIX, "; Changed temporary MUL,MOV into a MUL\n"); Result = true; continue; } @@ -3507,7 +3509,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("; Changed fake register by r1\n"); + DbgPrintf(LOG_PREFIX, "; Changed fake register by r1\n"); Result = true; continue; } @@ -3535,7 +3537,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("; Changed MOV into a NOP\n"); + DbgPrintf(LOG_PREFIX, "; Changed MOV into a NOP\n"); return true; } } @@ -3551,7 +3553,7 @@ 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("; Changed MOV 0 into a SUB v0,v0\n"); + DbgPrintf(LOG_PREFIX, "; Changed MOV 0 into a SUB v0,v0\n"); return true; } @@ -3588,7 +3590,7 @@ 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("; Changed MOV {const} into a SUB_factor 1-v0,-v0\n"); + DbgPrintf(LOG_PREFIX, "; Changed MOV {const} into a SUB_factor 1-v0,-v0\n"); return true; } return false; @@ -3601,7 +3603,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("; Changed ADD s0,0 into a MOV s0\n"); + DbgPrintf(LOG_PREFIX, "; Changed ADD s0,0 into a MOV s0\n"); return true; } return false; @@ -3615,7 +3617,7 @@ bool PSH_XBOX_SHADER::SimplifyMAD(PPSH_INTERMEDIATE_FORMAT Cur) // Change it into s2 : Cur->Opcode = PO_MOV; Cur->Parameters[0] = Cur->Parameters[2]; - DbgPrintf("; Changed MAD s0,0 into a MOV s0\n"); + DbgPrintf(LOG_PREFIX, "; Changed MAD s0,0 into a MOV s0\n"); return true; } @@ -3625,7 +3627,7 @@ bool PSH_XBOX_SHADER::SimplifyMAD(PPSH_INTERMEDIATE_FORMAT Cur) // Change it into s0+s2 : Cur->Opcode = PO_ADD; Cur->Parameters[1] = Cur->Parameters[2]; - DbgPrintf("; Changed MAD s0,1,s2 into a ADD s0,s2\n"); + DbgPrintf(LOG_PREFIX, "; Changed MAD s0,1,s2 into a ADD s0,s2\n"); return true; } @@ -3636,7 +3638,7 @@ bool PSH_XBOX_SHADER::SimplifyMAD(PPSH_INTERMEDIATE_FORMAT Cur) Cur->Opcode = PO_SUB; Cur->Parameters[1] = Cur->Parameters[0]; Cur->Parameters[0] = Cur->Parameters[2]; - DbgPrintf("; Changed MAD s0,-1,s2 into a SUB s2,s0\n"); + DbgPrintf(LOG_PREFIX, "; Changed MAD s0,-1,s2 into a SUB s2,s0\n"); return true; } return false; @@ -3649,7 +3651,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("; Changed SUB x, 0 into a MOV x\n"); + DbgPrintf(LOG_PREFIX, "; Changed SUB x, 0 into a MOV x\n"); return true; } return false; @@ -3663,7 +3665,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("; Changed MUL s0,0 into a MOV 0\n"); + DbgPrintf(LOG_PREFIX, "; Changed MUL s0,0 into a MOV 0\n"); return true; } @@ -3673,7 +3675,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("; Changed MUL s0,{const} into a MOV_factor s0\n"); + DbgPrintf(LOG_PREFIX, "; Changed MUL s0,{const} into a MOV_factor s0\n"); return true; } return false; @@ -3688,7 +3690,7 @@ bool PSH_XBOX_SHADER::SimplifyLRP(PPSH_INTERMEDIATE_FORMAT Cur) { // Change it into a MUL (calculating the left part : s0*s1 : Cur->Opcode = PO_MUL; - DbgPrintf("; Changed LRP s0,s1,s2 (where (1-s0)*s2=0) into a MUL s0,s1\n"); + DbgPrintf(LOG_PREFIX, "; Changed LRP s0,s1,s2 (where (1-s0)*s2=0) into a MUL s0,s1\n"); return true; } @@ -3699,7 +3701,7 @@ bool PSH_XBOX_SHADER::SimplifyLRP(PPSH_INTERMEDIATE_FORMAT Cur) Cur->Opcode = PO_MUL; Cur->Parameters[0].Invert(); Cur->Parameters[1] = Cur->Parameters[2]; - DbgPrintf("; Changed LRP s0,s1,s2 (where s0*s1=0) into a MUL (1-s0),s2\n"); + DbgPrintf(LOG_PREFIX, "; Changed LRP s0,s1,s2 (where s0*s1=0) into a MUL (1-s0),s2\n"); return true; } @@ -3710,7 +3712,7 @@ bool PSH_XBOX_SHADER::SimplifyLRP(PPSH_INTERMEDIATE_FORMAT Cur) Cur->Opcode = PO_MAD; Cur->Parameters[2] = Cur->Parameters[0]; Cur->Parameters[2].Invert(); - DbgPrintf("; Changed LRP s0,s1,1 into a MAD s0,s1,1-s0\n"); + DbgPrintf(LOG_PREFIX, "; Changed LRP s0,s1,1 into a MAD s0,s1,1-s0\n"); return true; } return false; @@ -4221,8 +4223,8 @@ static const if (hRet != D3D_OK) { - EmuWarning("Could not create pixel shader"); - EmuWarning(std::string((char*)pErrors->GetBufferPointer(), pErrors->GetBufferSize()).c_str()); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Could not create pixel shader"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, std::string((char*)pErrors->GetBufferPointer(), pErrors->GetBufferSize()).c_str()); printf(ConvertedPixelShaderStr.c_str()); @@ -4236,12 +4238,12 @@ static const /*ppCompilationErrors*/&pErrors); if (hRet != D3D_OK) { - EmuWarning("Could not create pixel shader"); - EmuWarning(std::string((char*)pErrors->GetBufferPointer(), pErrors->GetBufferSize()).c_str()); - XTL::CxbxKrnlCleanup("Cannot fall back to the most simple pixel shader!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Could not create pixel shader"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, std::string((char*)pErrors->GetBufferPointer(), pErrors->GetBufferSize()).c_str()); + XTL::CxbxKrnlCleanup(LOG_PREFIX, "Cannot fall back to the most simple pixel shader!"); } - EmuWarning("We're lying about the creation of a pixel shader!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "We're lying about the creation of a pixel shader!"); } if (pShader) @@ -4608,7 +4610,7 @@ inline void HandleInputOutput // 6928: check this as I doubt whether it works really like that /*if(strcmp(szInput[i], "r1")==0) { - // DbgPrintf("channel: %s\n", szChannels[i]); + // DbgPrintf(LOG_PREFIX, "channel: %s\n", szChannels[i]); // Sleep(3000); if((strcmp(szChannels[i], ".a")==0) && (!bR1AWritten)) { @@ -4813,7 +4815,7 @@ inline void HandleInputOutput //EmuWarningMsg("THIS IS WRONG, FIX ME!"); //if(!szOutput[1][0]) // strcpy(szOut1, szOutput[2]); - DbgPrintf("(!szOutput[0][0] || !szOutput[1][0]) && szOutput[2][0] = TRUE!\n"); + DbgPrintf(LOG_PREFIX, "(!szOutput[0][0] || !szOutput[1][0]) && szOutput[2][0] = TRUE!\n"); BOOL bUsable=TRUE; for(i=2; i<4; i++) @@ -4827,7 +4829,7 @@ inline void HandleInputOutput strcpy(szOut, szOutput[2]); - DbgPrintf("BUsable = TRUE, new output: %s\n", szOut); + DbgPrintf(LOG_PREFIX, "BUsable = TRUE, new output: %s\n", szOut); } else { @@ -5131,7 +5133,7 @@ inline void HandleInputOutput if (bEFProduct) { - EmuWarning("EF Product and V1R0 register used at the same time!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EF Product and V1R0 register used at the same time!"); } else { @@ -5652,7 +5654,7 @@ inline BOOL OptimizeOperation { if (szMod[0]) { - EmuWarning("Pixel Shader: Destination modifier present!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Destination modifier present!"); } switch (eOpTypes[2]) { @@ -5777,7 +5779,7 @@ inline BOOL OptimizeOperation { if (szOutputs[2][0] != 'r') { - EmuWarning("Pixel Shader: Destination not temporary register!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Destination not temporary register!"); } // ab input iOffset += sprintf(szCommand + iOffset, "mul%s r1, %s, %s\n", @@ -6109,7 +6111,7 @@ inline BOOL OptimizeOperation } if (!bHandled) { - EmuWarning("Unhandled pixel shader instruction!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unhandled pixel shader instruction!"); } // if (strcmp(szOps[2], "add") == 0) // { @@ -6123,7 +6125,7 @@ inline BOOL OptimizeOperation // } // else // { -// EmuWarning("Unhandled pixel shader instruction!"); +// EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unhandled pixel shader instruction!"); // } // } // else if (strcmp(szOps[2], "cnd") == 0) @@ -6138,12 +6140,12 @@ inline BOOL OptimizeOperation // } // else // { -// EmuWarning("Unhandled pixel shader instruction!"); +// EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unhandled pixel shader instruction!"); // } // } // else // { -// EmuWarning("Unhandled pixel shader instruction!"); +// EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unhandled pixel shader instruction!"); // } } } diff --git a/src/CxbxKrnl/EmuD3D8/PushBuffer.cpp b/src/CxbxKrnl/EmuD3D8/PushBuffer.cpp index e93b5231a..0da653af9 100644 --- a/src/CxbxKrnl/EmuD3D8/PushBuffer.cpp +++ b/src/CxbxKrnl/EmuD3D8/PushBuffer.cpp @@ -133,7 +133,7 @@ void XTL::EmuExecutePushBuffer { //Check whether Fixup exists or not. if (pFixup != NULL) { - LOG_TEST_CASE("PushBuffer has fixups"); + LOG_TEST_CASE(LOG_PREFIX, "PushBuffer has fixups"); //Interpret address of PushBuffer Data and Fixup Data UINT8* pPushBufferData = (UINT8*)pPushBuffer->Data; UINT8* pFixupData = (UINT8*)(pFixup->Data + pFixup->Run); @@ -187,7 +187,7 @@ DWORD CxbxGetStrideFromVertexShaderHandle(DWORD dwVertexShader) // Test-case : Prince of Persia: The Sands of Time [5553001d] // Test-case : RPM Tuning [Top Gear RPM Tuning] [4B420007] // Test-case : SpyHunter 2 [4D57001B] - //LOG_TEST_CASE("Non-FVF Vertex Shaders not yet (completely) supported for PushBuffer emulation!"); + //LOG_TEST_CASE(LOG_PREFIX, "Non-FVF Vertex Shaders not yet (completely) supported for PushBuffer emulation!"); CxbxVertexShader *pVertexShader = MapXboxVertexShaderHandleToCxbxVertexShader(dwVertexShader); if (pVertexShader) { @@ -196,7 +196,7 @@ DWORD CxbxGetStrideFromVertexShaderHandle(DWORD dwVertexShader) Stride = pVertexShader->VertexShaderInfo.VertexStreams[0].HostVertexStride; } else { - LOG_TEST_CASE("Non-FVF Vertex Shaders with multiple streams not supported for PushBuffer emulation!"); + LOG_TEST_CASE(LOG_PREFIX, "Non-FVF Vertex Shaders with multiple streams not supported for PushBuffer emulation!"); } } } @@ -205,7 +205,7 @@ DWORD CxbxGetStrideFromVertexShaderHandle(DWORD dwVertexShader) Stride = DxbxFVFToVertexSizeInBytes(dwVertexShader, /*bIncludeTextures=*/true); } else { - LOG_TEST_CASE("Invalid Vertex Shader not supported for PushBuffer emulation!"); + LOG_TEST_CASE(LOG_PREFIX, "Invalid Vertex Shader not supported for PushBuffer emulation!"); } } @@ -226,7 +226,7 @@ void HLE_pgraph_handle_method( // Skip all commands not intended for channel 0 (3D) if (subchannel > 0) { - LOG_TEST_CASE("Pushbuffer subchannel > 0"); + LOG_TEST_CASE(LOG_PREFIX, "Pushbuffer subchannel > 0"); return; // For now, don't even attempt to run through } @@ -240,7 +240,7 @@ void HLE_pgraph_handle_method( switch (method) { case 0: { - LOG_TEST_CASE("Pushbuffer method == 0"); + LOG_TEST_CASE(LOG_PREFIX, "Pushbuffer method == 0"); break; } case NV097_NO_OPERATION: { // 0x00000100, NV2A_NOP, No Operation, followed parameters are no use. this operation triggers DPC which is not implemented in HLE @@ -264,14 +264,14 @@ void HLE_pgraph_handle_method( case NV2A_VP_UPLOAD_CONST(3): { // Can't use NOINCREMENT_FLAG, parameters is constant matrix, 4X4 matrix has 16 DWORDs, maximum of 32 DWORD writes //load constant matrix to empty slot - LOG_TEST_CASE("NV2A_VP_UPLOAD_CONST"); + LOG_TEST_CASE(LOG_PREFIX, "NV2A_VP_UPLOAD_CONST"); break; } case NV097_SET_BEGIN_END: { // 0x000017FC, NV2A_VERTEX_BEGIN_END, D3DPUSH_SET_BEGIN_END, 1 DWORD parameter if (parameter == 0) { // Parameter == 0 means SetEnd, EndPush() // Trigger all draws from here if (pg->draw_arrays_length) { - LOG_TEST_CASE("PushBuffer : Draw Arrays"); + LOG_TEST_CASE(LOG_PREFIX, "PushBuffer : Draw Arrays"); assert(pg->inline_buffer_length == 0); assert(pg->inline_array_length == 0); assert(pg->inline_elements_length == 0); @@ -288,7 +288,7 @@ void HLE_pgraph_handle_method( #endif } else if (pg->inline_buffer_length) { - LOG_TEST_CASE("PushBuffer : Inline Buffer"); + LOG_TEST_CASE(LOG_PREFIX, "PushBuffer : Inline Buffer"); assert(pg->draw_arrays_length == 0); assert(pg->inline_array_length == 0); assert(pg->inline_elements_length == 0); @@ -337,7 +337,7 @@ void HLE_pgraph_handle_method( // retrieve vertex shader XTL::DWORD dwVertexShader = g_CurrentXboxVertexShaderHandle; if (dwVertexShader == 0) { - LOG_TEST_CASE("FVF Vertex Shader is null"); + LOG_TEST_CASE(LOG_PREFIX, "FVF Vertex Shader is null"); dwVertexShader = -1; } @@ -399,7 +399,7 @@ void HLE_pgraph_handle_method( #endif } else { - LOG_TEST_CASE("EMPTY NV097_SET_BEGIN_END"); + LOG_TEST_CASE(LOG_PREFIX, "EMPTY NV097_SET_BEGIN_END"); } } else { @@ -420,7 +420,7 @@ void HLE_pgraph_handle_method( break; } case NV097_ARRAY_ELEMENT16: { // 0x1800, NV2A_VB_ELEMENT_U16 - //LOG_TEST_CASE("NV2A_VB_ELEMENT_U16"); + //LOG_TEST_CASE(LOG_PREFIX, "NV2A_VB_ELEMENT_U16"); // Test-case : Turok (in main menu) // Test-case : Hunter Redeemer // Test-case : Otogi (see https://github.com/Cxbx-Reloaded/Cxbx-Reloaded/pull/1113#issuecomment-385593814) @@ -432,7 +432,7 @@ void HLE_pgraph_handle_method( break; } case NV097_ARRAY_ELEMENT32: { // 0x1808, NV2A_VB_ELEMENT_U32, Index Array Data - //LOG_TEST_CASE("NV2A_VB_ELEMENT_U32"); + //LOG_TEST_CASE(LOG_PREFIX, "NV2A_VB_ELEMENT_U32"); // Test-case : Turok (in main menu) assert(pg->inline_elements_length < NV2A_MAX_BATCH_LENGTH); pg__inline_elements[ @@ -463,13 +463,13 @@ void HLE_pgraph_handle_method( case NV097_SET_TRANSFORM_CONSTANT_LOAD: { // 0x00001EA4, NV2A_VP_UPLOAD_CONST_ID, D3DPUSH_SET_TRANSFORM_CONSTANT_LOAD // Add 96 to constant index parameter, one parameter=CONSTANT + 96 // Retrieve transform constant index and add 96 to it. - LOG_TEST_CASE("NV2A_VP_UPLOAD_CONST_ID"); + LOG_TEST_CASE(LOG_PREFIX, "NV2A_VP_UPLOAD_CONST_ID"); break; } default: { // default case, handling any other unknown methods. char message[256] = {}; sprintf(message, "Unhandled PushBuffer Operation : %s (0x%.04X)", NV2AMethodToString(method), method); - LOG_TEST_CASE(message); + LOG_TEST_CASE(LOG_PREFIX, message); break; } } // switch @@ -626,7 +626,7 @@ extern void XTL::EmuExecutePushBufferRaw while (dma_get != dma_put) { // Check if loop reaches end of pushbuffer if (dma_get >= dma_limit) { - LOG_TEST_CASE("Last pushbuffer instruction exceeds END of Data"); + LOG_TEST_CASE(LOG_PREFIX, "Last pushbuffer instruction exceeds END of Data"); // TODO : throw DMA_PUSHER(MEM_FAULT); return; // For now, don't even attempt to run through } @@ -661,18 +661,18 @@ extern void XTL::EmuExecutePushBufferRaw case COMMAND_TYPE_NONE: break; // fall through case COMMAND_TYPE_JUMP_LONG: - LOG_TEST_CASE("Pushbuffer COMMAND_TYPE_JUMP_LONG"); + LOG_TEST_CASE(LOG_PREFIX, "Pushbuffer COMMAND_TYPE_JUMP_LONG"); dma_get_jmp_shadow = dma_get; dma_get = (uint32_t *)(CONTIGUOUS_MEMORY_BASE | (word & COMMAND_WORD_MASK_JUMP_LONG)); continue; // while case COMMAND_TYPE_CALL: // Note : NV2A return is said not to work? if (subr_active) { - LOG_TEST_CASE("Pushbuffer COMMAND_TYPE_CALL while another call was active!"); + LOG_TEST_CASE(LOG_PREFIX, "Pushbuffer COMMAND_TYPE_CALL while another call was active!"); // TODO : throw DMA_PUSHER(CALL_SUBR_ACTIVE); return; // For now, don't even attempt to run through } else { - LOG_TEST_CASE("Pushbuffer COMMAND_TYPE_CALL"); + LOG_TEST_CASE(LOG_PREFIX, "Pushbuffer COMMAND_TYPE_CALL"); } subr_return = dma_get; @@ -680,7 +680,7 @@ extern void XTL::EmuExecutePushBufferRaw dma_get = (uint32_t *)(CONTIGUOUS_MEMORY_BASE | (word & COMMAND_WORD_MASK_JUMP_LONG)); continue; // while default: - LOG_TEST_CASE("Pushbuffer COMMAND_TYPE unknown"); + LOG_TEST_CASE(LOG_PREFIX, "Pushbuffer COMMAND_TYPE unknown"); // TODO : throw DMA_PUSHER(INVALID_CMD); return; // For now, don't even attempt to run through } // switch type @@ -690,7 +690,7 @@ extern void XTL::EmuExecutePushBufferRaw dma_state.ni = false; break; case COMMAND_INSTRUCTION_JUMP: - LOG_TEST_CASE("Pushbuffer COMMAND_INSTRUCTION_JUMP"); + LOG_TEST_CASE(LOG_PREFIX, "Pushbuffer COMMAND_INSTRUCTION_JUMP"); dma_get_jmp_shadow = dma_get; dma_get = (uint32_t *)(CONTIGUOUS_MEMORY_BASE | (word & COMMAND_WORD_MASK_JUMP)); continue; // while @@ -698,7 +698,7 @@ extern void XTL::EmuExecutePushBufferRaw dma_state.ni = true; break; default: - LOG_TEST_CASE("Pushbuffer COMMAND_INSTRUCTION unknown"); + LOG_TEST_CASE(LOG_PREFIX, "Pushbuffer COMMAND_INSTRUCTION unknown"); // TODO : throw DMA_PUSHER(INVALID_CMD); return; // For now, don't even attempt to run through } // switch instruction @@ -711,15 +711,15 @@ extern void XTL::EmuExecutePushBufferRaw break; // fall through case COMMAND_FLAGS_RETURN: // Note : NV2A return is said not to work? if (word != 0x00020000) { - LOG_TEST_CASE("Pushbuffer COMMAND_FLAGS_RETURN with additional bits?!"); + LOG_TEST_CASE(LOG_PREFIX, "Pushbuffer COMMAND_FLAGS_RETURN with additional bits?!"); return; // For now, don't even attempt to run through } else { - LOG_TEST_CASE("Pushbuffer COMMAND_FLAGS_RETURN"); + LOG_TEST_CASE(LOG_PREFIX, "Pushbuffer COMMAND_FLAGS_RETURN"); } if (!subr_active) { - LOG_TEST_CASE("Pushbuffer COMMAND_FLAGS_RETURN while another call was active!"); + LOG_TEST_CASE(LOG_PREFIX, "Pushbuffer COMMAND_FLAGS_RETURN while another call was active!"); // TODO : throw DMA_PUSHER(RET_SUBR_INACTIVE); return; // For now, don't even attempt to run through } @@ -729,15 +729,15 @@ extern void XTL::EmuExecutePushBufferRaw continue; // while default: if (command.flags == COMMAND_FLAGS_SLI_CONDITIONAL) { - LOG_TEST_CASE("Pushbuffer COMMAND_FLAGS_SLI_CONDITIONAL (NV40+) not available on NV2A"); + LOG_TEST_CASE(LOG_PREFIX, "Pushbuffer COMMAND_FLAGS_SLI_CONDITIONAL (NV40+) not available on NV2A"); } else if (command.flags == COMMAND_FLAGS_LONG_NON_INCREASING_METHODS) { - LOG_TEST_CASE("Pushbuffer COMMAND_FLAGS_LONG_NON_INCREASING_METHODS [IB-mode only] not available on NV2A"); + LOG_TEST_CASE(LOG_PREFIX, "Pushbuffer COMMAND_FLAGS_LONG_NON_INCREASING_METHODS [IB-mode only] not available on NV2A"); /// No need to do: dma_state.mthd = command.method; dma_state.ni = true; /// dma_state.mcnt = *dma_get++ & 0x00FFFFFF; // Long NI method command count is read from low 24 bits of next word /// dma_get += dma_state.mcnt; // To be safe, skip method data /// continue; } else { - LOG_TEST_CASE("Pushbuffer COMMAND_FLAGS unknown"); + LOG_TEST_CASE(LOG_PREFIX, "Pushbuffer COMMAND_FLAGS unknown"); } /// dma_get += command.method_count; // To be safe, skip method data diff --git a/src/CxbxKrnl/EmuD3D8/State.cpp b/src/CxbxKrnl/EmuD3D8/State.cpp index 1f108f0de..5a7726605 100644 --- a/src/CxbxKrnl/EmuD3D8/State.cpp +++ b/src/CxbxKrnl/EmuD3D8/State.cpp @@ -34,6 +34,7 @@ // * // ****************************************************************** #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX CXBXR_MODULE::D3DST #include "CxbxKrnl/Emu.h" #include "CxbxKrnl/EmuXTL.h" @@ -151,7 +152,7 @@ void XTL::EmuUpdateDeferredStates() if(v != 0 && v != 1 && v != 2 && v != 3 && v != 4 && v != 5 && v != 6 && v != 7 && v != 10 && v != 11 && v != 13 && v != 19 && v != 20 && v != 21 && v != 23 && v != 24 && v != 25 && v != 26 && v != 27 && v != 28 && v != 29 && v != 30 && v != 31 && v != 33) - EmuWarning("Unhandled RenderState Change @ %d (%d)", v, v + 82); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unhandled RenderState Change @ %d (%d)", v, v + 82); } } //**/ @@ -171,7 +172,7 @@ void XTL::EmuUpdateDeferredStates() if(pCur[0+Adjust2] != X_D3DTSS_UNK) { if(pCur[0+Adjust2] == 5) - EmuWarning("ClampToEdge is unsupported (temporarily)"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "ClampToEdge is unsupported (temporarily)"); else g_pD3DDevice->SetSamplerState(v, D3DSAMP_ADDRESSU, pCur[0 + Adjust2]); } @@ -179,7 +180,7 @@ void XTL::EmuUpdateDeferredStates() if(pCur[1+Adjust2] != X_D3DTSS_UNK) { if(pCur[1+Adjust2] == 5) - EmuWarning("ClampToEdge is unsupported (temporarily)"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "ClampToEdge is unsupported (temporarily)"); else g_pD3DDevice->SetSamplerState(v, D3DSAMP_ADDRESSV, pCur[1 + Adjust2]); } @@ -187,7 +188,7 @@ void XTL::EmuUpdateDeferredStates() if(pCur[2+Adjust2] != X_D3DTSS_UNK) { if(pCur[2+Adjust2] == 5) - EmuWarning("ClampToEdge is unsupported (temporarily)"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "ClampToEdge is unsupported (temporarily)"); else g_pD3DDevice->SetSamplerState(v, D3DSAMP_ADDRESSW, pCur[2 + Adjust2]); } @@ -195,7 +196,7 @@ void XTL::EmuUpdateDeferredStates() if(pCur[3+Adjust2] != X_D3DTSS_UNK) { if(pCur[3+Adjust2] == 4) - EmuWarning("QuinCunx is unsupported (temporarily)"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "QuinCunx is unsupported (temporarily)"); else g_pD3DDevice->SetSamplerState(v, D3DSAMP_MAGFILTER, pCur[3 + Adjust2]); } @@ -203,7 +204,7 @@ void XTL::EmuUpdateDeferredStates() if(pCur[4+Adjust2] != X_D3DTSS_UNK) { if(pCur[4+Adjust2] == 4) - EmuWarning("QuinCunx is unsupported (temporarily)"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "QuinCunx is unsupported (temporarily)"); else g_pD3DDevice->SetSamplerState(v, D3DSAMP_MINFILTER, pCur[4 + Adjust2]); } @@ -211,7 +212,7 @@ void XTL::EmuUpdateDeferredStates() if(pCur[5+Adjust2] != X_D3DTSS_UNK) { if(pCur[5+Adjust2] == 4) - EmuWarning("QuinCunx is unsupported (temporarily)"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "QuinCunx is unsupported (temporarily)"); else g_pD3DDevice->SetSamplerState(v, D3DSAMP_MIPFILTER, pCur[5 + Adjust2]); } @@ -309,7 +310,7 @@ void XTL::EmuUpdateDeferredStates() g_pD3DDevice->SetTextureStageState(v, D3DTSS_COLOROP, D3DTOP_BUMPENVMAPLUMINANCE); break; default: - EmuWarning("(Temporarily) Unsupported D3DTSS_COLOROP Value (%d)", pCur[12 - Adjust1]); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "(Temporarily) Unsupported D3DTSS_COLOROP Value (%d)", pCur[12 - Adjust1]); break; } } @@ -327,7 +328,7 @@ void XTL::EmuUpdateDeferredStates() if(pCur[16-Adjust1] != X_D3DTSS_UNK) { if(pCur[16-Adjust1] > 12 && pCur[16-Adjust1] != 14 && pCur[16-Adjust1] != 13) - EmuWarning("(Temporarily) Unsupported D3DTSS_ALPHAOP Value (%d)", pCur[16-Adjust1]); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "(Temporarily) Unsupported D3DTSS_ALPHAOP Value (%d)", pCur[16-Adjust1]); else if( pCur[16-Adjust1] == 14 ) g_pD3DDevice->SetTextureStageState(v, D3DTSS_ALPHAOP, D3DTOP_BLENDTEXTUREALPHA); @@ -380,7 +381,7 @@ void XTL::EmuUpdateDeferredStates() } if(pass) - EmuWarning("Unhandled TextureState Change @ %d->%d", v, r); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unhandled TextureState Change @ %d->%d", v, r); } } //**/ diff --git a/src/CxbxKrnl/EmuD3D8/VertexBuffer.cpp b/src/CxbxKrnl/EmuD3D8/VertexBuffer.cpp index 7643a6d61..173a30719 100755 --- a/src/CxbxKrnl/EmuD3D8/VertexBuffer.cpp +++ b/src/CxbxKrnl/EmuD3D8/VertexBuffer.cpp @@ -35,6 +35,7 @@ // * // ****************************************************************** #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX CXBXR_MODULE::VTXB #include "CxbxKrnl/VMManager.h" #include "CxbxKrnl/xxhash32.h" // For XXHash32::hash() @@ -104,7 +105,7 @@ bool GetCachedVertexBufferObject(DWORD pXboxDataPtr, DWORD size, XTL::IDirect3DV nullptr ); if (FAILED(hRet)) { - CxbxKrnlCleanup("Failed to create vertex buffer"); + CxbxKrnlCleanup(LOG_PREFIX, "Failed to create vertex buffer"); } g_HostVertexBuffers[pXboxDataPtr] = newBuffer; @@ -134,7 +135,7 @@ bool GetCachedVertexBufferObject(DWORD pXboxDataPtr, DWORD size, XTL::IDirect3DV nullptr ); if (FAILED(hRet)) { - CxbxKrnlCleanup("Failed to create vertex buffer"); + CxbxKrnlCleanup(LOG_PREFIX, "Failed to create vertex buffer"); } *pVertexBuffer = buffer->pHostVertexBuffer; @@ -165,7 +166,7 @@ void ActivatePatchedStream pPatchedStream->uiCachedHostVertexStride); //DEBUG_D3DRESULT(hRet, "g_pD3DDevice->SetStreamSource"); if (FAILED(hRet)) { - CxbxKrnlCleanup("Failed to set the type patched buffer as the new stream source!\n"); + CxbxKrnlCleanup(LOG_PREFIX, "Failed to set the type patched buffer as the new stream source!\n"); // TODO : Cartoon hits the above case when the vertex cache size is 0. } @@ -299,7 +300,7 @@ void XTL::CxbxVertexBufferConverter::ConvertStream if (bVshHandleIsFVF) { DWORD dwTexN = (XboxFVF & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT; if (dwTexN > X_D3DTS_STAGECOUNT) { - LOG_TEST_CASE("FVF,dwTexN > X_D3DTS_STAGECOUNT"); + LOG_TEST_CASE(LOG_PREFIX, "FVF,dwTexN > X_D3DTS_STAGECOUNT"); } // Check for active linear textures. @@ -348,7 +349,7 @@ void XTL::CxbxVertexBufferConverter::ConvertStream if (pDrawContext->pXboxVertexStreamZeroData != xbnullptr) { // There should only be one stream (stream zero) in this case if (uiStream != 0) { - CxbxKrnlCleanup("Trying to patch a Draw..UP with more than stream zero!"); + CxbxKrnlCleanup(LOG_PREFIX, "Trying to patch a Draw..UP with more than stream zero!"); } pXboxVertexData = (uint08 *)pDrawContext->pXboxVertexStreamZeroData; @@ -359,7 +360,7 @@ void XTL::CxbxVertexBufferConverter::ConvertStream if (bNeedStreamCopy) { pHostVertexData = (uint08*)malloc(dwHostVertexDataSize); if (pHostVertexData == nullptr) { - CxbxKrnlCleanup("Couldn't allocate the new stream zero buffer"); + CxbxKrnlCleanup(LOG_PREFIX, "Couldn't allocate the new stream zero buffer"); } } else { @@ -377,7 +378,7 @@ void XTL::CxbxVertexBufferConverter::ConvertStream 0); // DEBUG_D3DRESULT(hRet, "g_pD3DDevice->SetStreamSource"); if (FAILED(hRet)) { - EmuWarning("g_pD3DDevice->SetStreamSource(uiStream, nullptr, 0)"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "g_pD3DDevice->SetStreamSource(uiStream, nullptr, 0)"); } return; @@ -395,7 +396,7 @@ void XTL::CxbxVertexBufferConverter::ConvertStream GetCachedVertexBufferObject(pXboxVertexBuffer->Data, dwHostVertexDataSize, &pNewHostVertexBuffer); if (FAILED(pNewHostVertexBuffer->Lock(0, 0, (D3DLockData **)&pHostVertexData, D3DLOCK_DISCARD))) { - CxbxKrnlCleanup("Couldn't lock the new buffer"); + CxbxKrnlCleanup(LOG_PREFIX, "Couldn't lock the new buffer"); } // Copy stream for patching and caching. @@ -619,7 +620,7 @@ void XTL::CxbxVertexBufferConverter::ConvertStream } case X_D3DVSDT_NONE: { // 0x02: // Skip it // Test-case : WWE RAW2 - LOG_TEST_CASE("X_D3DVSDT_NONE"); + LOG_TEST_CASE(LOG_PREFIX, "X_D3DVSDT_NONE"); break; } default: { @@ -653,7 +654,7 @@ void XTL::CxbxVertexBufferConverter::ConvertStream if (bNeedTextureNormalization) { uiTextureCoordinatesByteOffsetInVertex = XTL::DxbxFVFToVertexSizeInBytes(XboxFVF, /*bIncludeTextures=*/false); if (bNeedVertexPatching) { - LOG_TEST_CASE("Potential xbox vs host texture-offset difference! (bNeedVertexPatching within bNeedTextureNormalization)"); + LOG_TEST_CASE(LOG_PREFIX, "Potential xbox vs host texture-offset difference! (bNeedVertexPatching within bNeedTextureNormalization)"); } // As long as vertices aren't resized / patched up until the texture coordinates, // the uiTextureCoordinatesByteOffsetInVertex on host will match Xbox @@ -667,14 +668,14 @@ void XTL::CxbxVertexBufferConverter::ConvertStream #if 0 // Check Z. TODO : Why reset Z from 0.0 to 1.0 ? (Maybe fog-related?) if (pVertexDataAsFloat[2] == 0.0f) { - // LOG_TEST_CASE("D3DFVF_XYZRHW (Z)"); // Test-case : Many XDK Samples (AlphaFog, PointSprites) + // LOG_TEST_CASE(LOG_PREFIX, "D3DFVF_XYZRHW (Z)"); // Test-case : Many XDK Samples (AlphaFog, PointSprites) pVertexDataAsFloat[2] = 1.0f; } #endif #if 1 // Check RHW. TODO : Why reset from 0.0 to 1.0 ? (Maybe 1.0 indicates that the vertices are not to be transformed) if (pVertexDataAsFloat[3] == 0.0f) { - // LOG_TEST_CASE("D3DFVF_XYZRHW (RHW)"); // Test-case : Many XDK Samples (AlphaFog, PointSprites) + // LOG_TEST_CASE(LOG_PREFIX, "D3DFVF_XYZRHW (RHW)"); // Test-case : Many XDK Samples (AlphaFog, PointSprites) pVertexDataAsFloat[3] = 1.0f; } #endif @@ -687,10 +688,10 @@ void XTL::CxbxVertexBufferConverter::ConvertStream if (pActivePixelContainer[i].bTexIsLinear) { switch (pActivePixelContainer[i].NrTexCoords) { case 0: - LOG_TEST_CASE("Normalize 0D?"); + LOG_TEST_CASE(LOG_PREFIX, "Normalize 0D?"); break; case 1: - LOG_TEST_CASE("Normalize 1D"); + LOG_TEST_CASE(LOG_PREFIX, "Normalize 1D"); pVertexUVData[0] /= pActivePixelContainer[i].Width; break; case 2: @@ -698,14 +699,14 @@ void XTL::CxbxVertexBufferConverter::ConvertStream pVertexUVData[1] /= pActivePixelContainer[i].Height; break; case 3: - LOG_TEST_CASE("Normalize 3D"); + LOG_TEST_CASE(LOG_PREFIX, "Normalize 3D"); // Test case : HeatShimmer pVertexUVData[0] /= pActivePixelContainer[i].Width; pVertexUVData[1] /= pActivePixelContainer[i].Height; pVertexUVData[2] /= pActivePixelContainer[i].Depth; break; default: - LOG_TEST_CASE("Normalize ?D"); + LOG_TEST_CASE(LOG_PREFIX, "Normalize ?D"); break; } } @@ -745,7 +746,7 @@ void XTL::CxbxVertexBufferConverter::ConvertStream void XTL::CxbxVertexBufferConverter::Apply(CxbxDrawContext *pDrawContext) { if ((pDrawContext->XboxPrimitiveType < X_D3DPT_POINTLIST) || (pDrawContext->XboxPrimitiveType > X_D3DPT_POLYGON)) - CxbxKrnlCleanup("Unknown primitive type: 0x%.02X\n", pDrawContext->XboxPrimitiveType); + CxbxKrnlCleanup(LOG_PREFIX, "Unknown primitive type: 0x%.02X\n", pDrawContext->XboxPrimitiveType); if (VshHandleIsVertexShader(pDrawContext->hVertexShader)) { m_pVertexShaderInfo = &(MapXboxVertexShaderHandleToCxbxVertexShader(pDrawContext->hVertexShader)->VertexShaderInfo); @@ -789,7 +790,7 @@ void XTL::CxbxVertexBufferConverter::Apply(CxbxDrawContext *pDrawContext) // Convex polygon is the same as a triangle fan. // No need to set : pDrawContext->XboxPrimitiveType = X_D3DPT_TRIANGLEFAN; // Test-case : Panzer Dragoon ORTA (when entering in-game) - LOG_TEST_CASE("X_D3DPT_POLYGON"); + LOG_TEST_CASE(LOG_PREFIX, "X_D3DPT_POLYGON"); } } @@ -801,24 +802,24 @@ VOID XTL::EmuFlushIVB() bool bFVF = VshHandleIsFVF(g_CurrentXboxVertexShaderHandle); DWORD dwCurFVF = (bFVF) ? g_CurrentXboxVertexShaderHandle : g_InlineVertexBuffer_FVF; - DbgPrintf("g_InlineVertexBuffer_TableOffset := %d\n", g_InlineVertexBuffer_TableOffset); + DbgPrintf(LOG_PREFIX, "g_InlineVertexBuffer_TableOffset := %d\n", g_InlineVertexBuffer_TableOffset); // Check the given FVF switch (dwCurFVF & D3DFVF_POSITION_MASK) { case 0: // No position ? if (bFVF) { - EmuWarning("EmuFlushIVB(): g_CurrentXboxVertexShaderHandle isn't a valid FVF - using D3DFVF_XYZRHW instead!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuFlushIVB(): g_CurrentXboxVertexShaderHandle isn't a valid FVF - using D3DFVF_XYZRHW instead!"); dwCurFVF |= D3DFVF_XYZRHW; } else { - EmuWarning("EmuFlushIVB(): using g_InlineVertexBuffer_FVF instead of current FVF!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuFlushIVB(): using g_InlineVertexBuffer_FVF instead of current FVF!"); dwCurFVF = g_InlineVertexBuffer_FVF; } break; case D3DFVF_XYZRHW: // D3DFVF_NORMAL isn't allowed in combination with D3DFVF_XYZRHW if (dwCurFVF & D3DFVF_NORMAL) { - EmuWarning("EmuFlushIVB(): Normal encountered while D3DFVF_XYZRHW is given - switching back to D3DFVF_XYZ!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuFlushIVB(): Normal encountered while D3DFVF_XYZRHW is given - switching back to D3DFVF_XYZ!"); dwCurFVF &= ~D3DFVF_POSITION_MASK; dwCurFVF |= D3DFVF_XYZ; } @@ -853,37 +854,37 @@ VOID XTL::EmuFlushIVB() *pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Position.z; if (dwPos == D3DFVF_XYZRHW) { *pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Rhw; - DbgPrintf("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); + 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); } else { // XYZRHW cannot be combined with NORMAL, but the other XYZ formats can : switch (dwPos) { case D3DFVF_XYZ: - DbgPrintf("IVB Position := {%f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Position.x, g_InlineVertexBuffer_Table[v].Position.y, g_InlineVertexBuffer_Table[v].Position.z); + 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); break; case D3DFVF_XYZB1: *pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Blend[0]; - DbgPrintf("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]); + 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]); break; case D3DFVF_XYZB2: *pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Blend[0]; *pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Blend[1]; - DbgPrintf("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]); + 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]); 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("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]); + 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]); 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("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]); + 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]); break; default: - CxbxKrnlCleanup("Unsupported Position Mask (FVF := 0x%.08X dwPos := 0x%.08X)", dwCurFVF, dwPos); + CxbxKrnlCleanup(LOG_PREFIX, "Unsupported Position Mask (FVF := 0x%.08X dwPos := 0x%.08X)", dwCurFVF, dwPos); break; } @@ -891,25 +892,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("IVB Normal := {%f, %f, %f}\n", g_InlineVertexBuffer_Table[v].Normal.x, g_InlineVertexBuffer_Table[v].Normal.y, 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); } } #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("IVB PointSize := 0x%.08X\n", g_InlineVertexBuffer_Table[v].PointSize); + DbgPrintf(LOG_PREFIX, "IVB PointSize := 0x%.08X\n", g_InlineVertexBuffer_Table[v].PointSize); } #endif if (dwCurFVF & D3DFVF_DIFFUSE) { *(DWORD*)pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Diffuse; - DbgPrintf("IVB Diffuse := 0x%.08X\n", g_InlineVertexBuffer_Table[v].Diffuse); + DbgPrintf(LOG_PREFIX, "IVB Diffuse := 0x%.08X\n", g_InlineVertexBuffer_Table[v].Diffuse); } if (dwCurFVF & D3DFVF_SPECULAR) { *(DWORD*)pVertexBufferData++ = g_InlineVertexBuffer_Table[v].Specular; - DbgPrintf("IVB Specular := 0x%.08X\n", g_InlineVertexBuffer_Table[v].Specular); + DbgPrintf(LOG_PREFIX, "IVB Specular := 0x%.08X\n", g_InlineVertexBuffer_Table[v].Specular); } for (uint i = 0; i < dwTexN; i++) { @@ -926,10 +927,10 @@ VOID XTL::EmuFlushIVB() if (g_bPrintfOn) { switch (TexSize[i]) { - case 1: DbgPrintf("IVB TexCoord%d := {%f}\n", i + 1, g_InlineVertexBuffer_Table[v].TexCoord[i].x); break; - case 2: DbgPrintf("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("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("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: 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; } } } @@ -937,7 +938,7 @@ VOID XTL::EmuFlushIVB() if (v == 0) { uint VertexBufferUsage = (uintptr_t)pVertexBufferData - (uintptr_t)g_InlineVertexBuffer_pData; if (VertexBufferUsage != uiStride) { - CxbxKrnlCleanup("EmuFlushIVB uses wrong stride!"); + CxbxKrnlCleanup(LOG_PREFIX, "EmuFlushIVB uses wrong stride!"); } } } diff --git a/src/CxbxKrnl/EmuD3D8/VertexShader.cpp b/src/CxbxKrnl/EmuD3D8/VertexShader.cpp index 1755ca215..ec44185ae 100644 --- a/src/CxbxKrnl/EmuD3D8/VertexShader.cpp +++ b/src/CxbxKrnl/EmuD3D8/VertexShader.cpp @@ -35,6 +35,7 @@ // * // ****************************************************************** #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX CXBXR_MODULE::VTXSH #define _DEBUG_TRACK_VS @@ -612,7 +613,7 @@ static void VshParseInstruction(uint32 *pShaderToken, pInstruction->A.Address = ConvertCRegister(VshGetField(pShaderToken, FLD_CONST)); break; default: - EmuWarning("Invalid instruction, parameter A type unknown %d", pInstruction->A.ParameterType); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Invalid instruction, parameter A type unknown %d", pInstruction->A.ParameterType); return; } pInstruction->A.Neg = VshGetField(pShaderToken, FLD_A_NEG); @@ -959,7 +960,7 @@ static void VshWriteShader(VSH_XBOX_SHADER *pShader, DisassemblyPos += sprintf(pDisassembly + DisassemblyPos, "%s", OReg_Name[pIntermediate->Output.Address]); break; default: - CxbxKrnlCleanup("Invalid output register in vertex shader!"); + CxbxKrnlCleanup(LOG_PREFIX, "Invalid output register in vertex shader!"); break; } VshWriteOutputMask(pIntermediate->Output.Mask, pDisassembly, &DisassemblyPos); @@ -1021,7 +1022,7 @@ static void VshVerifyBufferBounds(VSH_XBOX_SHADER *pShader) { if(pShader->IntermediateCount == VSH_MAX_INTERMEDIATE_COUNT) { - CxbxKrnlCleanup("Shader exceeds conversion buffer!"); + CxbxKrnlCleanup(LOG_PREFIX, "Shader exceeds conversion buffer!"); } } @@ -1408,7 +1409,7 @@ static void VshRemoveScreenSpaceInstructions(VSH_XBOX_SHADER *pShader) // them, or (c) doesn't reserve c-38 and c-37 for scale and offset. if(deleted != 3) { - EmuWarning("Applying screen space vertex shader patching hack!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Applying screen space vertex shader patching hack!"); for (int i = 0; i < pShader->IntermediateCount; i++) { VSH_INTERMEDIATE_FORMAT* pIntermediate = &pShader->Intermediate[i]; @@ -1473,7 +1474,7 @@ static void VshRemoveUndeclaredRegisters(VSH_XBOX_SHADER *pShader, bool *pDeclar bool used = pDeclaredRegisters[pIntermediate->Parameters[p].Parameter.Address]; if (!used) { - EmuWarning("Deleting usage of undeclared register v%d", pIntermediate->Parameters[p].Parameter.Address); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Deleting usage of undeclared register v%d", pIntermediate->Parameters[p].Parameter.Address); VshDeleteIntermediate(pShader, i); } } @@ -1585,7 +1586,7 @@ static boolean VshConvertShader(VSH_XBOX_SHADER *pShader, break; case 15: default: - LOG_TEST_CASE("exp instruction with invalid swizzle"); + LOG_TEST_CASE(LOG_PREFIX, "exp instruction with invalid swizzle"); break; } } @@ -1633,7 +1634,7 @@ static boolean VshConvertShader(VSH_XBOX_SHADER *pShader, if(pIntermediate->Output.Type != IMD_OUTPUT_R) { // TODO: Complete dph support - EmuWarning("Can't simulate dph for other than output r registers (yet)"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Can't simulate dph for other than output r registers (yet)"); // attempt to find unused register... int outRegister = -1; @@ -1734,7 +1735,7 @@ static boolean VshConvertShader(VSH_XBOX_SHADER *pShader, } if(R12Replacement == -1) { - EmuWarning("Vertex shader uses all r registers, including r12; impossible to convert!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Vertex shader uses all r registers, including r12; impossible to convert!"); return FALSE; } for (int j = 0; j < pShader->IntermediateCount; j++) @@ -1926,7 +1927,7 @@ static void VshConvertToken_NOP( // D3DVSD_NOP if(*pToken != DEF_VSH_NOP) { - EmuWarning("Token NOP found, but extra parameters are given!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Token NOP found, but extra parameters are given!"); } DbgVshPrintf("\tD3DVSD_NOP(),\n"); } @@ -2083,7 +2084,7 @@ static void VshConvertToken_STREAMDATA_SKIPBYTES( DbgVshPrintf("\tD3DVSD_SKIPBYTES(%d), /* xbox ext. */\n", SkipBytesCount); if (SkipBytesCount % sizeof(XTL::DWORD)) { - EmuWarning("D3DVSD_SKIPBYTES can't be converted to D3DVSD_SKIP, not divisble by 4."); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "D3DVSD_SKIPBYTES can't be converted to D3DVSD_SKIP, not divisble by 4."); } #ifdef CXBX_USE_D3D9 @@ -2342,7 +2343,7 @@ static void VshConvertToken_STREAMDATA_REG( if(HostVertexElementDataType == D3DDECLTYPE_UNUSED) { - EmuWarning("/* WARNING: Fatal type mismatch, no fitting type! */"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "/* WARNING: Fatal type mismatch, no fitting type! */"); } } @@ -2504,7 +2505,7 @@ extern HRESULT XTL::EmuRecompileVshFunction DWORD regNum = *pDeclToken & X_D3DVSD_VERTEXREGMASK; if (regNum >= temporaryCount /*12*/) { // Lego Star Wars hits this - LOG_TEST_CASE("RegNum > 12"); + LOG_TEST_CASE(LOG_PREFIX, "RegNum > 12"); pDeclToken++; continue; } @@ -2523,7 +2524,7 @@ extern HRESULT XTL::EmuRecompileVshFunction if(!pShader) { - EmuWarning("Couldn't allocate memory for vertex shader conversion buffer"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Couldn't allocate memory for vertex shader conversion buffer"); return E_OUTOFMEMORY; } pShader->ShaderHeader = *pShaderHeader; @@ -2532,15 +2533,15 @@ extern HRESULT XTL::EmuRecompileVshFunction case VERSION_XVS: break; case VERSION_XVSS: - EmuWarning("Might not support vertex state shaders?"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Might not support vertex state shaders?"); hRet = E_FAIL; break; case VERSION_XVSW: - EmuWarning("Might not support vertex read/write shaders?"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Might not support vertex read/write shaders?"); hRet = E_FAIL; break; default: - EmuWarning("Unknown vertex shader version 0x%02X", pShaderHeader->Version); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unknown vertex shader version 0x%02X", pShaderHeader->Version); hRet = E_FAIL; break; } @@ -2563,7 +2564,7 @@ extern HRESULT XTL::EmuRecompileVshFunction // Do not attempt to compile empty shaders if (pShader->IntermediateCount == 0) { - EmuWarning("Skipped empty Vertex Shader"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Skipped empty Vertex Shader"); return STATUS_INVALID_PARAMETER; } @@ -2583,7 +2584,7 @@ extern HRESULT XTL::EmuRecompileVshFunction // HACK: Azurik. Prevent Direct3D from trying to assemble this. if(!strcmp(pShaderDisassembly, "vs.2.x\n")) { - EmuWarning("Replacing empty vertex shader with fallback"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Replacing empty vertex shader with fallback"); static const char dummy[] = "vs.2.x\n" @@ -2615,8 +2616,8 @@ extern HRESULT XTL::EmuRecompileVshFunction if (FAILED(hRet)) { - EmuWarning("Couldn't assemble recompiled vertex shader"); - EmuWarning("%s", pErrors->GetBufferPointer()); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Couldn't assemble recompiled vertex shader"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "%s", pErrors->GetBufferPointer()); } if( pErrors ) diff --git a/src/CxbxKrnl/EmuDSound.cpp b/src/CxbxKrnl/EmuDSound.cpp index 4fe768dc5..32063e109 100755 --- a/src/CxbxKrnl/EmuDSound.cpp +++ b/src/CxbxKrnl/EmuDSound.cpp @@ -36,14 +36,13 @@ // * // ****************************************************************** #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX CXBXR_MODULE::DSOUND // prevent name collisions namespace xboxkrnl { #include }; -#define LOG_PREFIX CXBXR_MODULE::DSOUND - #include #include #include "CxbxKrnl.h" @@ -218,7 +217,7 @@ static void dsound_thread_worker(LPVOID); #define RETURN_RESULT_CHECK(hRet) { \ static bool bPopupShown = false; if (!bPopupShown && hRet) { bPopupShown = true; \ printf("Return result report: 0x%08X\nIn %s (%s)\n", hRet, __func__, __FILE__); \ - EmuWarning("An issue has been found. Please report game title and console's output of return result," \ + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "An issue has been found. Please report game title and console's output of return result," \ " function, and file name to https://github.com/Cxbx-Reloaded/Cxbx-Reloaded/issues/485"); } return hRet; } #include "EmuDSoundInline.hpp" @@ -303,13 +302,13 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreate) } if (dsErrorMsg != nullptr) { - CxbxKrnlCleanup(dsErrorMsg, hRet); + CxbxKrnlCleanup(LOG_PREFIX, dsErrorMsg, hRet); } hRet = g_pDSound8->SetCooperativeLevel(g_hEmuWindow, DSSCL_PRIORITY); if (hRet != DS_OK) { - CxbxKrnlCleanup("g_pDSound8->SetCooperativeLevel Failed!"); + CxbxKrnlCleanup(LOG_PREFIX, "g_pDSound8->SetCooperativeLevel Failed!"); } // clear sound buffer cache @@ -337,7 +336,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreate) hRet = g_pDSound8->CreateSoundBuffer(&bufferDesc, &g_pDSoundPrimaryBuffer, nullptr); if (hRet != DS_OK) { - CxbxKrnlCleanup("Creating primary buffer for DirectSound Failed!"); + CxbxKrnlCleanup(LOG_PREFIX, "Creating primary buffer for DirectSound Failed!"); } /* Quote from MDSN "For the primary buffer, you must use the @@ -350,7 +349,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreate) hRet = g_pDSoundPrimaryBuffer->QueryInterface(IID_IDirectSound3DListener8, (LPVOID*)&g_pDSoundPrimary3DListener8); if (hRet != DS_OK) { - CxbxKrnlCleanup("Creating primary 3D Listener for DirectSound Failed!"); + CxbxKrnlCleanup(LOG_PREFIX, "Creating primary 3D Listener for DirectSound Failed!"); } initialized = true; @@ -936,7 +935,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateBuffer) hRet = XTL::EMUPATCH(DirectSoundCreate)(NULL, &g_pDSound8, NULL); if (hRet != DS_OK) { - CxbxKrnlCleanup("Unable to initialize DirectSound!"); + CxbxKrnlCleanup(LOG_PREFIX, "Unable to initialize DirectSound!"); } } @@ -962,7 +961,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateBuffer) DWORD dwAcceptableMask = 0x00000010 | 0x00000020 | 0x00000080 | 0x00000100 | 0x00020000 | 0x00040000 /*| 0x00080000*/; if (pdsbd->dwFlags & (~dwAcceptableMask)) { - EmuWarning("Use of unsupported pdsbd->dwFlags mask(s) (0x%.08X)", pdsbd->dwFlags & (~dwAcceptableMask)); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Use of unsupported pdsbd->dwFlags mask(s) (0x%.08X)", pdsbd->dwFlags & (~dwAcceptableMask)); } // HACK: Hot fix for titles not giving CTRL3D flag. Xbox might accept it, however the host does not. @@ -985,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("EmuDSound: DirectSoundCreateBuffer, *ppBuffer := 0x%08X, bytes := 0x%08X\n", *ppBuffer, (*ppBuffer)->EmuBufferDesc.dwBufferBytes); + DbgPrintf(LOG_PREFIX, "DirectSoundCreateBuffer, *ppBuffer := 0x%08X, bytes := 0x%08X\n", *ppBuffer, (*ppBuffer)->EmuBufferDesc.dwBufferBytes); DSoundBufferCreate(&DSBufferDesc, (*ppBuffer)->EmuDirectSoundBuffer8); if (pdsbd->dwFlags & DSBCAPS_CTRL3D) { @@ -1218,7 +1217,7 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSoundBuffer_Lock) } if (hRet != DS_OK) { - CxbxKrnlCleanup("DirectSoundBuffer Lock Failed!"); + CxbxKrnlCleanup(LOG_PREFIX, "DirectSoundBuffer Lock Failed!"); } // Host lock position @@ -1486,7 +1485,7 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSoundBuffer_SetCurrentPosition) HRESULT hRet = pThis->EmuDirectSoundBuffer8->SetCurrentPosition(dwNewPosition); if (hRet != DS_OK) { - EmuWarning("SetCurrentPosition Failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "SetCurrentPosition Failed!"); } leaveCriticalSection; @@ -1545,7 +1544,7 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSoundBuffer_Play) pThis->X_lock.dwLockBytes2); if (dwFlags & ~(X_DSBPLAY_LOOPING | X_DSBPLAY_FROMSTART | X_DSBPLAY_SYNCHPLAYBACK)) { - CxbxKrnlCleanup("Unsupported Playing Flags"); + CxbxKrnlCleanup(LOG_PREFIX, "Unsupported Playing Flags"); } pThis->EmuPlayFlags = dwFlags; @@ -1568,7 +1567,7 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSoundBuffer_Play) if (hRet == DS_OK) { if (dwFlags & X_DSBPLAY_FROMSTART) { if (pThis->EmuDirectSoundBuffer8->SetCurrentPosition(0) != DS_OK) { - EmuWarning("Rewinding buffer failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Rewinding buffer failed!"); } } if ((pThis->EmuFlags & DSE_FLAG_SYNCHPLAYBACK_CONTROL) == 0) { @@ -1738,7 +1737,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateStream) hRet = XTL::EMUPATCH(DirectSoundCreate)(NULL, &g_pDSound8, NULL); if (hRet != DS_OK) { - CxbxKrnlCleanup("Unable to initialize DirectSound!"); + CxbxKrnlCleanup(LOG_PREFIX, "Unable to initialize DirectSound!"); } } @@ -1766,7 +1765,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateStream) DWORD dwAcceptableMask = 0x00000010; // TODO: Note 0x00040000 is being ignored (DSSTREAMCAPS_LOCDEFER) if (pdssd->dwFlags & (~dwAcceptableMask)) { - EmuWarning("Use of unsupported pdssd->dwFlags mask(s) (0x%.08X)", pdssd->dwFlags & (~dwAcceptableMask)); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Use of unsupported pdssd->dwFlags mask(s) (0x%.08X)", pdssd->dwFlags & (~dwAcceptableMask)); } DSBufferDesc.dwSize = sizeof(DSBUFFERDESC); //DSBufferDesc->dwFlags = (pdssd->dwFlags & dwAcceptableMask) | DSBCAPS_CTRLVOLUME | DSBCAPS_GETCURRENTPOSITION2; @@ -1799,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("EmuDSound: DirectSoundCreateStream, *ppStream := 0x%.08X\n", *ppStream); + DbgPrintf(LOG_PREFIX, "DirectSoundCreateStream, *ppStream := 0x%.08X\n", *ppStream); DSoundBufferCreate(&DSBufferDesc, (*ppStream)->EmuDirectSoundBuffer8); if (DSBufferDesc.dwFlags & DSBCAPS_CTRL3D) { @@ -1859,7 +1858,7 @@ VOID WINAPI XTL::EMUPATCH(CMcpxStream_Dummy_0x10)(DWORD dwDummy1, DWORD dwDummy2 // Causes deadlock in Halo... // TODO: Verify that this is a Vista related problem (I HATE Vista!) -// EmuWarning("EmuCMcpxStream_Dummy_0x10 is ignored!"); +// EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuCMcpxStream_Dummy_0x10 is ignored!"); leaveCriticalSection; @@ -1991,7 +1990,7 @@ HRESULT WINAPI XTL::EMUPATCH(CDirectSoundStream_GetInfo) LOG_FUNC_END; // TODO: A (real) implementation? - EmuWarning("EmuDirectSound_CDirectSoundStream_GetInfo is not yet supported!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuDirectSound_CDirectSoundStream_GetInfo is not yet supported!"); if (pInfo) { pInfo->dwFlags = XMO_STREAMF_FIXED_SAMPLE_SIZE; @@ -2132,7 +2131,7 @@ HRESULT WINAPI XTL::EMUPATCH(CDirectSoundStream_Process) //TODO: What to do with output buffer audio variable? Need test case or functional source code. // NOTE: pOutputBuffer is reserved, must be set to NULL from titles. if (pOutputBuffer != xbnullptr) { - LOG_TEST_CASE("pOutputBuffer is not nullptr, please report title test case to issue tracker. Thanks!"); + LOG_TEST_CASE(LOG_PREFIX, "pOutputBuffer is not nullptr, please report title test case to issue tracker. Thanks!"); } } else { @@ -3005,7 +3004,7 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSound_EnableHeadphones) LOG_FUNC_END; //Windows Vista and later does not set speaker configuration from SetSpeakerConfig function. - EmuWarning("EmuIDirectSound_EnableHeadphones ignored"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuIDirectSound_EnableHeadphones ignored"); leaveCriticalSection; @@ -3311,7 +3310,7 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSoundBuffer_PlayEx) //TODO: Need implement support for rtTimeStamp. if (rtTimeStamp != 0) { - EmuWarning("Not implemented for rtTimeStamp greater than 0 of %08d", rtTimeStamp); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Not implemented for rtTimeStamp greater than 0 of %08d", rtTimeStamp); } HRESULT hRet = XTL::EMUPATCH(IDirectSoundBuffer_Play)(pThis, NULL, NULL, dwFlags); @@ -3348,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("X_DSCAPS: dwFree2DBuffers = %8X | dwFree3DBuffers = %8X | dwFreeBufferSGEs = %08X | dwMemAlloc = %08X\n", pDSCaps->dwFree2DBuffers, pDSCaps->dwFree3DBuffers, pDSCaps->dwFreeBufferSGEs, pDSCaps->dwMemoryAllocated); + DbgPrintf(LOG_PREFIX, "X_DSCAPS: dwFree2DBuffers = %8X | dwFree3DBuffers = %8X | dwFreeBufferSGEs = %08X | dwMemAlloc = %08X\n", pDSCaps->dwFree2DBuffers, pDSCaps->dwFree3DBuffers, pDSCaps->dwFreeBufferSGEs, pDSCaps->dwMemoryAllocated); } leaveCriticalSection; @@ -3729,12 +3728,12 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSoundBuffer_SetNotificationPositions) if (hRet == DS_OK) { hRet = pNotify->SetNotificationPositions(dwNotifyCount, paNotifies); if (hRet != DS_OK) { - EmuWarning("Could not set notification position(s)!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Could not set notification position(s)!"); } pNotify->Release(); } else { - EmuWarning("Could not create notification interface!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Could not create notification interface!"); } } } diff --git a/src/CxbxKrnl/EmuDSoundInline.hpp b/src/CxbxKrnl/EmuDSoundInline.hpp index b680091bb..4b15c94f3 100644 --- a/src/CxbxKrnl/EmuDSoundInline.hpp +++ b/src/CxbxKrnl/EmuDSoundInline.hpp @@ -99,7 +99,7 @@ inline void XADPCM2PCMFormat(LPWAVEFORMATEX lpwfxFormat) { #if 0 //For testing purpose if XADPCM to PCM is not accurate. - DbgPrintf("EmuDSound: XADPCM WAVEFORMATEX\n" + DbgPrintf(LOG_PREFIX, "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("EmuDSound: Converted to PCM WAVEFORMATEX\n" + DbgPrintf(LOG_PREFIX, "EmuDSound: Converted to PCM WAVEFORMATEX\n" "{\n" " wFormatTag : 0x%.04hX\n" " nChannels : 0x%.02hd\n" @@ -255,7 +255,7 @@ inline void GeneratePCMFormat( bIsSpecial = true; dwEmuFlags |= DSE_FLAG_RECIEVEDATA; - EmuWarning("Creating dummy WAVEFORMATEX (pdsbd->lpwfxFormat = xbnullptr)..."); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Creating dummy WAVEFORMATEX (pdsbd->lpwfxFormat = xbnullptr)..."); // HACK: This is a special sound buffer, create dummy WAVEFORMATEX data. // It's supposed to recieve data rather than generate it. Buffers created @@ -407,7 +407,7 @@ inline void DSoundBufferCreate(LPDSBUFFERDESC pDSBufferDesc, LPDIRECTSOUNDBUFFER inline void DSound3DBufferCreate(LPDIRECTSOUNDBUFFER8 pDSBuffer, LPDIRECTSOUND3DBUFFER8 &pDS3DBuffer) { HRESULT hRetDS3D = pDSBuffer->QueryInterface(IID_IDirectSound3DBuffer, (LPVOID*)&(pDS3DBuffer)); if (hRetDS3D != DS_OK) { - EmuWarning("CreateSound3DBuffer Failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "CreateSound3DBuffer Failed!"); pDS3DBuffer = nullptr; } } @@ -735,7 +735,7 @@ inline void DSoundStreamClearPacket( BOOL checkHandle = SetEvent(unionEventContext); if (checkHandle == 0) { DWORD error = GetLastError(); - EmuWarning("DSOUND: Unable to set event on packet's hCompletionEvent. %8X | error = %8X", unionEventContext, error); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unable to set event on packet's hCompletionEvent. %8X | error = %8X", unionEventContext, error); } } } @@ -942,7 +942,7 @@ inline HRESULT HybridDirectSoundBuffer_GetCurrentPosition( HRESULT hRet = pDSBuffer->GetCurrentPosition(&dwCurrentPlayCursor, &dwCurrentWriteCursor); if (hRet != DS_OK) { - EmuWarning("GetCurrentPosition Failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "GetCurrentPosition Failed!"); } if (pdwCurrentPlayCursor != xbnullptr) { @@ -1070,7 +1070,7 @@ inline HRESULT HybridDirectSoundBuffer_Play( // rewind buffer if ((dwFlags & X_DSBPLAY_FROMSTART)) { if (pDSBuffer->SetCurrentPosition(0) != DS_OK) { - EmuWarning("Rewinding buffer failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Rewinding buffer failed!"); } dwFlags &= ~X_DSBPLAY_FROMSTART; @@ -1729,7 +1729,7 @@ inline HRESULT HybridDirectSoundBuffer_SetVolume( if (lVolume <= -6400 && lVolume != DSBVOLUME_MIN) { lVolume = DSBVOLUME_MIN; } else if (lVolume > 0) { - EmuWarning("HybridDirectSoundBuffer_SetVolume has received greater than 0: %ld", lVolume); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "HybridDirectSoundBuffer_SetVolume has received greater than 0: %ld", lVolume); lVolume = 0; } if ((dwEmuFlags & DSE_FLAG_DEBUG_MUTE) > 0) { diff --git a/src/CxbxKrnl/EmuFS.cpp b/src/CxbxKrnl/EmuFS.cpp index d4312fc45..20a2bdc66 100644 --- a/src/CxbxKrnl/EmuFS.cpp +++ b/src/CxbxKrnl/EmuFS.cpp @@ -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("INIT: Patching FS Register Accesses\n"); + DbgPrintf(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("INIT: Searching for FS Instruction in section %s\n", CxbxKrnl_Xbe->m_szSectionName[sectionIndex]); + DbgPrintf(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("INIT: Patching FS Instruction at 0x%.8X\n", addr); + DbgPrintf(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("INIT: Done patching FS Register Accesses\n"); + DbgPrintf(CXBXR_MODULE::INIT, "Done patching FS Register Accesses\n"); } // generate fs segment selector @@ -579,16 +579,16 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData) #ifdef _DEBUG_TRACE // dump raw TLS data if (pNewTLS == nullptr) { - DbgPrintf("KRNL: TLS Non-Existant (OK)\n"); + DbgPrintf(LOG_PREFIX, "TLS Non-Existant (OK)\n"); } else { - DbgPrintf("KRNL: TLS Data Dump...\n"); + DbgPrintf(LOG_PREFIX, "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("KRNL: 0x%.8X:", (xbaddr)bByte); + DbgPrintf(LOG_PREFIX, "0x%.8X:", (xbaddr)bByte); } // Note : Use printf instead of DbgPrintf here, which prefixes with GetCurrentThreadId() : @@ -664,5 +664,5 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData) // Make the KPCR struct available to KeGetPcr() EmuKeSetPcr(NewPcr); - DbgPrintf("KRNL: Installed KPCR in TIB_ArbitraryDataSlot (with pTLS = 0x%.8X)\n", pTLS); + DbgPrintf(LOG_PREFIX, "Installed KPCR in TIB_ArbitraryDataSlot (with pTLS = 0x%.8X)\n", pTLS); } diff --git a/src/CxbxKrnl/EmuFile.cpp b/src/CxbxKrnl/EmuFile.cpp index 10271687c..b3194144d 100644 --- a/src/CxbxKrnl/EmuFile.cpp +++ b/src/CxbxKrnl/EmuFile.cpp @@ -94,7 +94,7 @@ void CxbxCreatePartitionHeaderFile(std::string filename, bool partition0 = false { HANDLE hf = CreateFile(filename.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0); if (!hf) { - CxbxKrnlCleanup("CxbxCreatePartitionHeaderFile Failed\nUnable to create file: %s (%s)", filename); + CxbxKrnlCleanup(LOG_PREFIX, "CxbxCreatePartitionHeaderFile Failed\nUnable to create file: %s (%s)", filename); return; } @@ -114,7 +114,7 @@ XboxPartitionTable CxbxGetPartitionTable() XboxPartitionTable table; FILE* fp = fopen((CxbxBasePath + "Partition0.bin").c_str(), "rb"); if (fp == nullptr) { - CxbxKrnlCleanup("CxbxGetPartitionTable Failed:\nUnable to open file: %s", (CxbxBasePath + "Partition0.bin").c_str()); + CxbxKrnlCleanup(LOG_PREFIX, "CxbxGetPartitionTable Failed:\nUnable to open file: %s", (CxbxBasePath + "Partition0.bin").c_str()); } fread(&table, sizeof(XboxPartitionTable), 1, fp); @@ -150,7 +150,7 @@ int CxbxGetPartitionNumberFromHandle(HANDLE hFile) // Get which partition number is being accessed, by parsing the filename and extracting the last portion char buffer[MAX_PATH] = {0}; if (!GetFinalPathNameByHandle(hFile, buffer, MAX_PATH, VOLUME_NAME_DOS)) { - CxbxKrnlCleanup("CxbxGetPartitionNumberFromHandle Failed:\nUnable to determine path for HANDLE 0x%08X", hFile); + CxbxKrnlCleanup(LOG_PREFIX, "CxbxGetPartitionNumberFromHandle Failed:\nUnable to determine path for HANDLE 0x%08X", hFile); } std::string bufferString(buffer); @@ -166,7 +166,7 @@ std::string CxbxGetPartitionDataPathFromHandle(HANDLE hFile) // Get which partition number is being accessed, by parsing the filename and extracting the last portion char buffer[MAX_PATH] = {0}; if (!GetFinalPathNameByHandle(hFile, buffer, MAX_PATH, VOLUME_NAME_DOS)) { - CxbxKrnlCleanup("CxbxGetPartitionDataPathFromHandle Failed:\nUnable to determine path for HANDLE 0x%08X", hFile); + CxbxKrnlCleanup(LOG_PREFIX, "CxbxGetPartitionDataPathFromHandle Failed:\nUnable to determine path for HANDLE 0x%08X", hFile); } std::string bufferString(buffer); @@ -181,7 +181,7 @@ void CxbxFormatPartitionByHandle(HANDLE hFile) // Sanity check, make sure we are actually deleting something within the Cxbx-Reloaded folder if (partitionPath.find("Cxbx-Reloaded") == std::string::npos) { - EmuWarning("Attempting to format a path that is not within a Cxbx-Reloaded data folder... Ignoring!\n"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Attempting to format a path that is not within a Cxbx-Reloaded data folder... Ignoring!\n"); return; } @@ -378,7 +378,7 @@ NTSTATUS CxbxConvertFilePath( NtSymbolicLinkObject = FindNtSymbolicLinkObjectByRootHandle(g_hCurDir); RelativePath.erase(0, 5); // Remove '$HOME' } else - CxbxKrnlCleanup(("Unsupported path macro : " + OriginalPath).c_str()); + CxbxKrnlCleanup(LOG_PREFIX, ("Unsupported path macro : " + OriginalPath).c_str()); } // Check if the path starts with a relative path indicator : else if (RelativePath[0] == '.') // "4x4 Evo 2" needs this @@ -439,7 +439,7 @@ NTSTATUS CxbxConvertFilePath( replace_all( RelativePath, "\\\\", "\\" ); if (g_bPrintfOn) { - DbgPrintf("FILE: %s Corrected path...\n", aFileAPIName.c_str()); + DbgPrintf(LOG_PREFIX, "%s Corrected path...\n", aFileAPIName.c_str()); printf(" Org:\"%s\"\n", OriginalPath.c_str()); if (_strnicmp(HostPath.c_str(), CxbxBasePath.c_str(), CxbxBasePath.length()) == 0) { printf(" New:\"$CxbxPath\\%s%s\"\n", (HostPath.substr(CxbxBasePath.length(), std::string::npos)).c_str(), RelativePath.c_str()); @@ -649,12 +649,12 @@ NTSTATUS EmuNtSymbolicLinkObject::Init(std::string aSymbolicLinkName, std::strin if (RootDirectoryHandle == INVALID_HANDLE_VALUE) { result = STATUS_DEVICE_DOES_NOT_EXIST; // TODO : Is this the correct error? - CxbxKrnlCleanup((std::string("Could not map ") + HostSymbolicLinkPath).c_str()); + CxbxKrnlCleanup(LOG_PREFIX, (std::string("Could not map ") + HostSymbolicLinkPath).c_str()); } else { NtSymbolicLinkObjects[DriveLetter - 'A'] = this; - DbgPrintf("FILE: Linked \"%s\" to \"%s\" (residing at \"%s\")\n", aSymbolicLinkName.c_str(), aFullPath.c_str(), HostSymbolicLinkPath.c_str()); + DbgPrintf(LOG_PREFIX, "Linked \"%s\" to \"%s\" (residing at \"%s\")\n", aSymbolicLinkName.c_str(), aFullPath.c_str(), HostSymbolicLinkPath.c_str()); } } } diff --git a/src/CxbxKrnl/EmuKrnl.cpp b/src/CxbxKrnl/EmuKrnl.cpp index c1192cf86..fab1534a6 100644 --- a/src/CxbxKrnl/EmuKrnl.cpp +++ b/src/CxbxKrnl/EmuKrnl.cpp @@ -156,7 +156,7 @@ extern DWORD ExecuteDpcQueue(); void KiUnexpectedInterrupt() { xboxkrnl::KeBugCheck(TRAP_CAUSE_UNKNOWN); // see - CxbxKrnlCleanup("Unexpected Software Interrupt!"); + CxbxKrnlCleanup(LOG_PREFIX, "Unexpected Software Interrupt!"); } void CallSoftwareInterrupt(const xboxkrnl::KIRQL SoftwareIrql) @@ -166,7 +166,7 @@ void CallSoftwareInterrupt(const xboxkrnl::KIRQL SoftwareIrql) KiUnexpectedInterrupt(); break; case APC_LEVEL: // = 1 // HalpApcInterrupt - EmuWarning("Unimplemented Software Interrupt (APC)"); // TODO : ExecuteApcQueue(); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unimplemented Software Interrupt (APC)"); // TODO : ExecuteApcQueue(); break; case DISPATCH_LEVEL: // = 2 ExecuteDpcQueue(); diff --git a/src/CxbxKrnl/EmuKrnl.h b/src/CxbxKrnl/EmuKrnl.h index 2a32f9466..d7e29c85c 100644 --- a/src/CxbxKrnl/EmuKrnl.h +++ b/src/CxbxKrnl/EmuKrnl.h @@ -103,7 +103,7 @@ public: } __except (EmuException(GetExceptionInformation())) { - EmuWarning("Problem with ExceptionFilter!"); + EmuLog(CXBXR_MODULE::KRNL, LOG_LEVEL::WARNING, "Problem with ExceptionFilter!"); } } private: diff --git a/src/CxbxKrnl/EmuKrnlAv.cpp b/src/CxbxKrnl/EmuKrnlAv.cpp index 6b2b223d5..3d11c61e3 100644 --- a/src/CxbxKrnl/EmuKrnlAv.cpp +++ b/src/CxbxKrnl/EmuKrnlAv.cpp @@ -53,7 +53,7 @@ namespace NtDll #include "EmuNtDll.h" }; -#include "Emu.h" // For EmuWarning() +#include "Emu.h" // For EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, ) #include "EmuXTL.h" #include "EmuX86.h" diff --git a/src/CxbxKrnl/EmuKrnlDbg.cpp b/src/CxbxKrnl/EmuKrnlDbg.cpp index 1cfa2e0c7..46f07fb7a 100644 --- a/src/CxbxKrnl/EmuKrnlDbg.cpp +++ b/src/CxbxKrnl/EmuKrnlDbg.cpp @@ -54,7 +54,7 @@ namespace NtDll }; -#include "Emu.h" // For EmuWarning() +#include "Emu.h" // For EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, ) // ****************************************************************** // * 0x0005 - DbgBreakPoint() diff --git a/src/CxbxKrnl/EmuKrnlEx.cpp b/src/CxbxKrnl/EmuKrnlEx.cpp index bb81ff2f2..abb45d697 100644 --- a/src/CxbxKrnl/EmuKrnlEx.cpp +++ b/src/CxbxKrnl/EmuKrnlEx.cpp @@ -56,7 +56,7 @@ namespace NtDll }; #include "CxbxKrnl.h" // For CxbxKrnlCleanup -#include "Emu.h" // For EmuWarning() +#include "Emu.h" // For EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, ) #include "EmuKrnl.h" // For InsertHeadList, InsertTailList, RemoveHeadList #include // for std::atomic @@ -145,7 +145,7 @@ static bool eeprom_data_is_valid(xboxkrnl::XC_VALUE_INDEX index) checksum = eeprom_section_checksum(FactorySettings_data, sizeof(EEPROM->FactorySettings)); } else { - EmuWarning("WARNING: Eeprom ValueIndex 0x%X does not have a checksum\n", index); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Eeprom ValueIndex 0x%X does not have a checksum\n", index); } return checksum == valid_checksum; } diff --git a/src/CxbxKrnl/EmuKrnlFs.cpp b/src/CxbxKrnl/EmuKrnlFs.cpp index 485093c35..521f57c88 100644 --- a/src/CxbxKrnl/EmuKrnlFs.cpp +++ b/src/CxbxKrnl/EmuKrnlFs.cpp @@ -36,7 +36,7 @@ // ****************************************************************** #define _XBOXKRNL_DEFEXTRN_ -#define LOG_PREFIX CXBXR_MODULE::FS +#define LOG_PREFIX CXBXR_MODULE::FSC // prevent name collisions namespace xboxkrnl @@ -53,7 +53,7 @@ namespace NtDll #include "EmuNtDll.h" }; -#include "Emu.h" // For EmuWarning() +#include "Emu.h" // For EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, ) #define FSCACHE_MAXIMUM_NUMBER_OF_CACHE_PAGES 2048 diff --git a/src/CxbxKrnl/EmuKrnlHal.cpp b/src/CxbxKrnl/EmuKrnlHal.cpp index fab76d37b..50b3db720 100644 --- a/src/CxbxKrnl/EmuKrnlHal.cpp +++ b/src/CxbxKrnl/EmuKrnlHal.cpp @@ -48,7 +48,7 @@ namespace xboxkrnl #include "Logging.h" // For LOG_FUNC() #include "EmuKrnlLogging.h" #include "CxbxKrnl.h" // For CxbxKrnlCleanup, CxbxConvertArgToString, and CxbxExec -#include "Emu.h" // For EmuWarning() +#include "Emu.h" // For EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, ) #include "EmuKrnl.h" #include "EmuX86.h" // HalReadWritePciSpace needs this #include "EmuShared.h" @@ -239,7 +239,7 @@ XBSYSAPI EXPORTNUM(44) xboxkrnl::ULONG NTAPI xboxkrnl::HalGetInterruptVector *Irql = (KIRQL)VECTOR2IRQL(dwVector); #ifdef _DEBUG_TRACE - DbgPrintf("KRNL: HalGetInterruptVector(): Interrupt vector requested for %d (%s)\n", + DbgPrintf(LOG_PREFIX, "HalGetInterruptVector(): Interrupt vector requested for %d (%s)\n", BusInterruptLevel, IRQNames[BusInterruptLevel]); #endif } @@ -478,7 +478,7 @@ XBSYSAPI EXPORTNUM(49) xboxkrnl::VOID DECLSPEC_NORETURN NTAPI xboxkrnl::HalRetur switch (Routine) { case ReturnFirmwareHalt: - CxbxKrnlCleanup("Emulated Xbox is halted"); + CxbxKrnlCleanup(LOG_PREFIX, "Emulated Xbox is halted"); break; case ReturnFirmwareReboot: @@ -583,7 +583,7 @@ XBSYSAPI EXPORTNUM(49) xboxkrnl::VOID DECLSPEC_NORETURN NTAPI xboxkrnl::HalRetur CxbxConvertArgToString(szProcArgsBuffer, szFilePath_CxbxReloaded_Exe, XbePath.c_str(), CxbxKrnl_hEmuParent, CxbxKrnl_DebugMode, CxbxKrnl_DebugFileName.c_str()); if (!CxbxExec(szProcArgsBuffer, nullptr, false)) { - CxbxKrnlCleanup("Could not launch %s", XbePath.c_str()); + CxbxKrnlCleanup(LOG_PREFIX, "Could not launch %s", XbePath.c_str()); } } } @@ -605,7 +605,7 @@ XBSYSAPI EXPORTNUM(49) xboxkrnl::VOID DECLSPEC_NORETURN NTAPI xboxkrnl::HalRetur CxbxConvertArgToString(szProcArgsBuffer, szFilePath_CxbxReloaded_Exe, szFilePath_Xbe, CxbxKrnl_hEmuParent, CxbxKrnl_DebugMode, CxbxKrnl_DebugFileName.c_str()); if (!CxbxExec(szProcArgsBuffer, nullptr, false)) { - CxbxKrnlCleanup("Could not launch %s", szFilePath_Xbe); + CxbxKrnlCleanup(LOG_PREFIX, "Could not launch %s", szFilePath_Xbe); } break; } diff --git a/src/CxbxKrnl/EmuKrnlIo.cpp b/src/CxbxKrnl/EmuKrnlIo.cpp index becb22769..9cfe6f086 100644 --- a/src/CxbxKrnl/EmuKrnlIo.cpp +++ b/src/CxbxKrnl/EmuKrnlIo.cpp @@ -47,7 +47,7 @@ namespace xboxkrnl #include "Logging.h" // For LOG_FUNC() #include "EmuKrnlLogging.h" #include "CxbxKrnl.h" // For CxbxKrnlCleanup -#include "Emu.h" // For EmuWarning() +#include "Emu.h" // For EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, ) #include "EmuFile.h" // For CxbxCreateSymbolicLink(), etc. #include "CxbxDebugger.h" @@ -303,11 +303,11 @@ XBSYSAPI EXPORTNUM(66) xboxkrnl::NTSTATUS NTAPI xboxkrnl::IoCreateFile if (FAILED(ret)) { - EmuWarning("KRNL: IoCreateFile Failed! (%s)\n", NtStatusToString(ret)); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "IoCreateFile Failed! (%s)\n", NtStatusToString(ret)); } else { - DbgPrintf("KRNL: IoCreateFile = 0x%.8X\n", *FileHandle); + DbgPrintf(LOG_PREFIX, "IoCreateFile = 0x%.8X\n", *FileHandle); } RETURN(LOG_PREFIX, ret); diff --git a/src/CxbxKrnl/EmuKrnlKe.cpp b/src/CxbxKrnl/EmuKrnlKe.cpp index 8783f30c6..950444a46 100644 --- a/src/CxbxKrnl/EmuKrnlKe.cpp +++ b/src/CxbxKrnl/EmuKrnlKe.cpp @@ -54,7 +54,7 @@ namespace NtDll }; #include "CxbxKrnl.h" // For CxbxKrnlCleanup -#include "Emu.h" // For EmuWarning() +#include "Emu.h" // For EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, ) #include "EmuKrnl.h" // For InitializeListHead(), etc. #include "EmuKrnlKi.h" // For KiRemoveTreeTimer(), KiInsertTreeTimer() #include "EmuFile.h" // For IsEmuHandle(), NtStatusToString() @@ -97,7 +97,7 @@ xboxkrnl::KPCR* KeGetPcr() Pcr = (xboxkrnl::PKPCR)__readfsdword(TIB_ArbitraryDataSlot); if (Pcr == nullptr) { - EmuWarning("KeGetPCR returned nullptr: Was this called from a non-xbox thread?"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "KeGetPCR returned nullptr: Was this called from a non-xbox thread?"); // Attempt to salvage the situation by calling InitXboxThread to setup KPCR in place InitXboxThread(g_CPUXbox); Pcr = (xboxkrnl::PKPCR)__readfsdword(TIB_ArbitraryDataSlot); @@ -160,7 +160,7 @@ DWORD ExecuteDpcQueue() pkdpc->Inserted = FALSE; // Set DpcRoutineActive to support KeIsExecutingDpc: KeGetCurrentPrcb()->DpcRoutineActive = TRUE; // Experimental - DbgPrintf("KRNL: Global DpcQueue, calling DPC at 0x%.8X\n", pkdpc->DeferredRoutine); + DbgPrintf(LOG_PREFIX, "Global DpcQueue, calling DPC at 0x%.8X\n", pkdpc->DeferredRoutine); __try { // Call the Deferred Procedure : pkdpc->DeferredRoutine( @@ -170,7 +170,7 @@ DWORD ExecuteDpcQueue() pkdpc->SystemArgument2); } __except (EmuException(GetExceptionInformation())) { - EmuWarning("Problem with ExceptionFilter!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Problem with ExceptionFilter!"); } KeGetCurrentPrcb()->DpcRoutineActive = FALSE; // Experimental @@ -204,7 +204,7 @@ DWORD ExecuteDpcQueue() if (pkdpc == nullptr) break; // while - DbgPrintf("KRNL: Global TimerQueue, calling DPC at 0x%.8X\n", pkdpc->DeferredRoutine); + DbgPrintf(LOG_PREFIX, "Global TimerQueue, calling DPC at 0x%.8X\n", pkdpc->DeferredRoutine); __try { pkdpc->DeferredRoutine( @@ -214,7 +214,7 @@ DWORD ExecuteDpcQueue() pkdpc->SystemArgument2); } __except (EmuException(GetExceptionInformation())) { - EmuWarning("Problem with ExceptionFilter!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Problem with ExceptionFilter!"); } } } @@ -235,7 +235,7 @@ void InitDpcAndTimerThread() InitializeListHead(&(g_DpcData.DpcQueue)); InitializeListHead(&(g_DpcData.TimerQueue)); - DbgPrintf("INIT: Creating DPC event\n"); + DbgPrintf(CXBXR_MODULE::INIT, "Creating DPC event\n"); g_DpcData.DpcEvent = CreateEvent(/*lpEventAttributes=*/nullptr, /*bManualReset=*/FALSE, /*bInitialState=*/FALSE, /*lpName=*/nullptr); } @@ -396,7 +396,7 @@ XBSYSAPI EXPORTNUM(96) xboxkrnl::NTSTATUS NTAPI xboxkrnl::KeBugCheckEx int result = MessageBoxA(g_hEmuWindow, buffer, "KeBugCheck", MB_YESNO | MB_ICONWARNING); if (result == IDNO) { - CxbxKrnlCleanup(NULL); + CxbxKrnlCleanup(LOG_PREFIX, NULL); } KeBugCheckIgnored = true; @@ -1055,7 +1055,7 @@ XBSYSAPI EXPORTNUM(123) xboxkrnl::LONG NTAPI xboxkrnl::KePulseEvent // Fetch the host event and signal it, if present if (g_KeEventHandles.find(Event) == g_KeEventHandles.end()) { - EmuWarning("KePulseEvent called on a non-existant event!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "KePulseEvent called on a non-existant event!"); } else { PulseEvent(g_KeEventHandles[Event]); @@ -1120,9 +1120,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("host tick count : %lu\n", CxbxRdTsc(/*xbox=*/false)); + DbgPrintf(LOG_PREFIX, "host tick count : %lu\n", CxbxRdTsc(/*xbox=*/false)); ret = CxbxRdTsc(/*xbox=*/true); - DbgPrintf("emulated tick count : %lu\n", ret); + DbgPrintf(LOG_PREFIX, "emulated tick count : %lu\n", ret); RETURN(LOG_PREFIX, ret); } @@ -1381,7 +1381,7 @@ XBSYSAPI EXPORTNUM(138) xboxkrnl::LONG NTAPI xboxkrnl::KeResetEvent // Fetch the host event and signal it, if present if (g_KeEventHandles.find(Event) == g_KeEventHandles.end()) { - EmuWarning("KeResetEvent called on a non-existant event!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "KeResetEvent called on a non-existant event!"); } else { ResetEvent(g_KeEventHandles[Event]); @@ -1523,7 +1523,7 @@ XBSYSAPI EXPORTNUM(145) xboxkrnl::LONG NTAPI xboxkrnl::KeSetEvent // Fetch the host event and signal it, if present if (g_KeEventHandles.find(Event) == g_KeEventHandles.end()) { - EmuWarning("KeSetEvent called on a non-existant event. Creating it!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "KeSetEvent called on a non-existant event. Creating it!"); // TODO: Find out why some XDKs do not call KeInitializeEvent first //We can check the event type from the internal structure, see https://www.geoffchappell.com/studies/windows/km/ntoskrnl/structs/kobjects.htm?tx=111 @@ -1631,7 +1631,7 @@ XBSYSAPI EXPORTNUM(150) xboxkrnl::BOOLEAN NTAPI xboxkrnl::KeSetTimerEx LARGE_INTEGER SystemTime; if (Timer->Header.Type != TimerNotificationObject && Timer->Header.Type != TimerSynchronizationObject) { - CxbxKrnlCleanup("Assertion: '(Timer)->Header.Type == TimerNotificationObject) || ((Timer)->Header.Type == TimerSynchronizationObject)' in KeSetTimerEx()"); + CxbxKrnlCleanup(LOG_PREFIX, "Assertion: '(Timer)->Header.Type == TimerNotificationObject) || ((Timer)->Header.Type == TimerSynchronizationObject)' in KeSetTimerEx()"); } // Same as KeCancelTimer(Timer) : @@ -1807,7 +1807,7 @@ XBSYSAPI EXPORTNUM(158) xboxkrnl::NTSTATUS NTAPI xboxkrnl::KeWaitForMultipleObje std::vector ntdllObjects; for (uint i = 0; i < Count; i++) { - DbgPrintf("Object: 0x%08X\n", Object[i]); + DbgPrintf(LOG_PREFIX, "Object: 0x%08X\n", Object[i]); if (g_KeEventHandles.find((PKEVENT)Object[i]) == g_KeEventHandles.end()) { ntdllObjects.push_back(Object[i]); } else { @@ -1828,7 +1828,7 @@ XBSYSAPI EXPORTNUM(158) xboxkrnl::NTSTATUS NTAPI xboxkrnl::KeWaitForMultipleObje (NtDll::PLARGE_INTEGER)Timeout); if (FAILED(ret)) - EmuWarning("KeWaitForMultipleObjects failed! (%s)", NtStatusToString(ret)); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "KeWaitForMultipleObjects failed! (%s)", NtStatusToString(ret)); } if (nativeObjects.size() > 0) { @@ -1840,7 +1840,7 @@ XBSYSAPI EXPORTNUM(158) xboxkrnl::NTSTATUS NTAPI xboxkrnl::KeWaitForMultipleObje (NtDll::PLARGE_INTEGER)Timeout); if (FAILED(ret)) - EmuWarning("KeWaitForMultipleObjects failed! (%s)", NtStatusToString(ret)); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "KeWaitForMultipleObjects failed! (%s)", NtStatusToString(ret)); } RETURN(LOG_PREFIX, ret); diff --git a/src/CxbxKrnl/EmuKrnlMm.cpp b/src/CxbxKrnl/EmuKrnlMm.cpp index 498b83062..1e0e1c9ac 100644 --- a/src/CxbxKrnl/EmuKrnlMm.cpp +++ b/src/CxbxKrnl/EmuKrnlMm.cpp @@ -49,7 +49,7 @@ namespace xboxkrnl #include "EmuKrnl.h" // For DefaultLaunchDataPage #include "EmuKrnlLogging.h" #include "CxbxKrnl.h" // For CxbxKrnlCleanup -#include "Emu.h" // For EmuWarning() +#include "Emu.h" // For EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, ) #include "VMManager.h" #include "EmuShared.h" #include @@ -407,8 +407,8 @@ XBSYSAPI EXPORTNUM(181) xboxkrnl::NTSTATUS NTAPI xboxkrnl::MmQueryStatistics if (!MemoryStatistics) { - EmuWarning("KNRL: MmQueryStatistics : PMM_STATISTICS MemoryStatistics is nullptr!\n"); - LOG_IGNORED(); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "MmQueryStatistics : PMM_STATISTICS MemoryStatistics is nullptr!\n"); + LOG_IGNORED(LOG_PREFIX); RETURN(LOG_PREFIX, STATUS_INVALID_PARAMETER); } @@ -416,21 +416,21 @@ XBSYSAPI EXPORTNUM(181) xboxkrnl::NTSTATUS NTAPI xboxkrnl::MmQueryStatistics { g_VMManager.MemoryStatistics(MemoryStatistics); - DbgPrintf(" MemoryStatistics->Length = 0x%.08X\n", MemoryStatistics->Length); - DbgPrintf(" MemoryStatistics->TotalPhysicalPages = 0x%.08X\n", MemoryStatistics->TotalPhysicalPages); - DbgPrintf(" MemoryStatistics->AvailablePages = 0x%.08X\n", MemoryStatistics->AvailablePages); - DbgPrintf(" MemoryStatistics->VirtualMemoryBytesCommitted = 0x%.08X\n", MemoryStatistics->VirtualMemoryBytesCommitted); - DbgPrintf(" MemoryStatistics->VirtualMemoryBytesReserved = 0x%.08X\n", MemoryStatistics->VirtualMemoryBytesReserved); - DbgPrintf(" MemoryStatistics->CachePagesCommitted = 0x%.08X\n", MemoryStatistics->CachePagesCommitted); - DbgPrintf(" MemoryStatistics->PoolPagesCommitted = 0x%.08X\n", MemoryStatistics->PoolPagesCommitted); - DbgPrintf(" MemoryStatistics->StackPagesCommitted = 0x%.08X\n", MemoryStatistics->StackPagesCommitted); - DbgPrintf(" MemoryStatistics->ImagePagesCommitted = 0x%.08X\n", MemoryStatistics->ImagePagesCommitted); + 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); ret = STATUS_SUCCESS; } else { - EmuWarning("KRNL: MmQueryStatistics with unusual size -> 0x%.8X", MemoryStatistics->Length); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "MmQueryStatistics with unusual size -> 0x%.8X", MemoryStatistics->Length); ret = STATUS_INVALID_PARAMETER; } diff --git a/src/CxbxKrnl/EmuKrnlNt.cpp b/src/CxbxKrnl/EmuKrnlNt.cpp index adbee4396..49bf28fb8 100644 --- a/src/CxbxKrnl/EmuKrnlNt.cpp +++ b/src/CxbxKrnl/EmuKrnlNt.cpp @@ -54,7 +54,7 @@ namespace NtDll }; #include "CxbxKrnl.h" // For CxbxKrnlCleanup -#include "Emu.h" // For EmuWarning() +#include "Emu.h" // For EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, ) #include "EmuFile.h" // For EmuNtSymbolicLinkObject, NtStatusToString(), etc. #include "VMManager.h" // For g_VMManager #include "CxbxDebugger.h" @@ -117,9 +117,9 @@ XBSYSAPI EXPORTNUM(185) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCancelTimer /*OUT*/CurrentState); if (FAILED(ret)) - EmuWarning("NtCancelTimer failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtCancelTimer failed!"); - RETURN(LOG_PREFIX, LOG_PREFIX, ret); + RETURN(LOG_PREFIX, ret); } // ****************************************************************** @@ -135,7 +135,7 @@ XBSYSAPI EXPORTNUM(186) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtClearEvent NTSTATUS ret = NtDll::NtClearEvent(EventHandle); if (FAILED(ret)) - EmuWarning("NtClearEvent Failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtClearEvent Failed!"); RETURN(LOG_PREFIX, ret); } @@ -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( "Closing duplicate handle...\n" ); + DbgPrintf(LOG_PREFIX, "Closing duplicate handle...\n" ); CloseHandle( g_DuplicateHandles[Handle] ); g_DuplicateHandles.erase(Handle); @@ -218,9 +218,9 @@ XBSYSAPI EXPORTNUM(188) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateDirectoryObje } if (FAILED(ret)) - EmuWarning("NtCreateDirectoryObject Failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtCreateDirectoryObject Failed!"); else - DbgPrintf("KRNL: NtCreateDirectoryObject DirectoryHandle = 0x%.8X\n", *DirectoryHandle); + DbgPrintf(LOG_PREFIX, "NtCreateDirectoryObject DirectoryHandle = 0x%.8X\n", *DirectoryHandle); RETURN(LOG_PREFIX, ret); } @@ -283,7 +283,7 @@ XBSYSAPI EXPORTNUM(189) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateEvent if (FAILED(ret)) { - EmuWarning("Trying fallback (without object attributes)...\nError code 0x%X", ret); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Trying fallback (without object attributes)...\nError code 0x%X", ret); // If it fails, try again but without the object attributes stucture // This fixes Panzer Dragoon games on non-Vista OSes. @@ -295,12 +295,12 @@ XBSYSAPI EXPORTNUM(189) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateEvent InitialState); if(FAILED(ret)) - EmuWarning("NtCreateEvent Failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtCreateEvent Failed!"); else - DbgPrintf("KRNL: NtCreateEvent EventHandle = 0x%.8X\n", *EventHandle); + DbgPrintf(LOG_PREFIX, "NtCreateEvent EventHandle = 0x%.8X\n", *EventHandle); } else - DbgPrintf("KRNL: NtCreateEvent EventHandle = 0x%.8X\n", *EventHandle); + DbgPrintf(LOG_PREFIX, "NtCreateEvent EventHandle = 0x%.8X\n", *EventHandle); RETURN(LOG_PREFIX, ret); } @@ -413,7 +413,7 @@ XBSYSAPI EXPORTNUM(192) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateMutant if (FAILED(ret)) { - EmuWarning("Trying fallback (without object attributes)...\nError code 0x%X", ret); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Trying fallback (without object attributes)...\nError code 0x%X", ret); // If it fails, try again but without the object attributes stucture ret = NtDll::NtCreateMutant( @@ -423,12 +423,12 @@ XBSYSAPI EXPORTNUM(192) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateMutant InitialOwner); if(FAILED(ret)) - EmuWarning("NtCreateMutant Failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtCreateMutant Failed!"); else - DbgPrintf("KRNL: NtCreateMutant MutantHandle = 0x%.8X\n", *MutantHandle); + DbgPrintf(LOG_PREFIX, "NtCreateMutant MutantHandle = 0x%.8X\n", *MutantHandle); } else - DbgPrintf("KRNL: NtCreateMutant MutantHandle = 0x%.8X\n", *MutantHandle); + DbgPrintf(LOG_PREFIX, "NtCreateMutant MutantHandle = 0x%.8X\n", *MutantHandle); RETURN(LOG_PREFIX, ret); } @@ -487,7 +487,7 @@ XBSYSAPI EXPORTNUM(193) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateSemaphore if (FAILED(ret)) { - EmuWarning("Trying fallback (without object attributes)...\nError code 0x%X", ret); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Trying fallback (without object attributes)...\nError code 0x%X", ret); // If it fails, try again but without the object attributes stucture ret = NtDll::NtCreateSemaphore( @@ -498,12 +498,12 @@ XBSYSAPI EXPORTNUM(193) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateSemaphore MaximumCount); if(FAILED(ret)) - EmuWarning("NtCreateSemaphore failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtCreateSemaphore failed!"); else - DbgPrintf("KRNL: NtCreateSemaphore SemaphoreHandle = 0x%.8X\n", *SemaphoreHandle); + DbgPrintf(LOG_PREFIX, "NtCreateSemaphore SemaphoreHandle = 0x%.8X\n", *SemaphoreHandle); } else - DbgPrintf("KRNL: NtCreateSemaphore SemaphoreHandle = 0x%.8X\n", *SemaphoreHandle); + DbgPrintf(LOG_PREFIX, "NtCreateSemaphore SemaphoreHandle = 0x%.8X\n", *SemaphoreHandle); RETURN(LOG_PREFIX, ret); } @@ -561,9 +561,9 @@ XBSYSAPI EXPORTNUM(194) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtCreateTimer ); if (FAILED(ret)) - EmuWarning("NtCreateTimer failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtCreateTimer failed!"); else - DbgPrintf("KRNL: NtCreateTimer TimerHandle = 0x%.8X\n", *TimerHandle); + DbgPrintf(LOG_PREFIX, "NtCreateTimer TimerHandle = 0x%.8X\n", *TimerHandle); RETURN(LOG_PREFIX, ret); } @@ -591,7 +591,7 @@ XBSYSAPI EXPORTNUM(195) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtDeleteFile } if (FAILED(ret)) - EmuWarning("NtDeleteFile Failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtDeleteFile Failed!"); RETURN(LOG_PREFIX, ret); } @@ -728,7 +728,7 @@ XBSYSAPI EXPORTNUM(197) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtDuplicateObject } if (ret != STATUS_SUCCESS) - EmuWarning("Object was not duplicated!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Object was not duplicated!"); RETURN(LOG_PREFIX, ret); } @@ -904,9 +904,9 @@ XBSYSAPI EXPORTNUM(203) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtOpenSymbolicLinkObj } if (ret != STATUS_SUCCESS) - EmuWarning("NtOpenSymbolicLinkObject failed! (%s)", NtStatusToString(ret)); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtOpenSymbolicLinkObject failed! (%s)", NtStatusToString(ret)); else - DbgPrintf("KRNL: NtOpenSymbolicLinkObject LinkHandle^ = 0x%.8X", *LinkHandle); + DbgPrintf(LOG_PREFIX, "NtOpenSymbolicLinkObject LinkHandle^ = 0x%.8X", *LinkHandle); RETURN(LOG_PREFIX, ret); } @@ -958,7 +958,7 @@ XBSYSAPI EXPORTNUM(205) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtPulseEvent /*OUT*/PreviousState); if (FAILED(ret)) - EmuWarning("NtPulseEvent failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtPulseEvent failed!"); RETURN(LOG_PREFIX, ret); } @@ -1004,15 +1004,15 @@ XBSYSAPI EXPORTNUM(206) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueueApcThread if( FAILED( ret ) ) { - EmuWarning( "Duplicating handle with THREAD_SET_CONTEXT..." ); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Duplicating handle with THREAD_SET_CONTEXT..." ); // If we get here, then attempt to duplicate the thread. if(!DuplicateHandle(g_CurrentProcessHandle, ThreadHandle, g_CurrentProcessHandle, &hApcThread, THREAD_SET_CONTEXT,FALSE,0)) - EmuWarning("DuplicateHandle failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "DuplicateHandle failed!"); else { g_DuplicateHandles[ThreadHandle] = hApcThread; // Save this thread because we'll need to de-reference it later - DbgPrintf( "DuplicateHandle returned 0x%X (ThreadId 0x%.4X)\n", hApcThread, GetThreadId( hApcThread ) ); + DbgPrintf(LOG_PREFIX, "DuplicateHandle returned 0x%X (ThreadId 0x%.4X)\n", hApcThread, GetThreadId( hApcThread ) ); } @@ -1025,7 +1025,7 @@ XBSYSAPI EXPORTNUM(206) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueueApcThread } if (FAILED(ret)) { - EmuWarning("NtQueueApcThread failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtQueueApcThread failed!"); CloseHandle( g_DuplicateHandles[ThreadHandle] ); g_DuplicateHandles.erase( ThreadHandle ); } @@ -1066,7 +1066,7 @@ XBSYSAPI EXPORTNUM(207) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryDirectoryFile NTSTATUS ret; if (FileInformationClass != FileDirectoryInformation) // Due to unicode->string conversion - CxbxKrnlCleanup("Unsupported FileInformationClass"); + CxbxKrnlCleanup(LOG_PREFIX, "Unsupported FileInformationClass"); NtDll::UNICODE_STRING NtFileMask; @@ -1182,7 +1182,7 @@ XBSYSAPI EXPORTNUM(209) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryEvent /*ReturnLength=*/nullptr); if (ret != STATUS_SUCCESS) - EmuWarning("NtQueryEvent failed! (%s)", NtStatusToString(ret)); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtQueryEvent failed! (%s)", NtStatusToString(ret)); RETURN(LOG_PREFIX, ret); } @@ -1219,7 +1219,7 @@ XBSYSAPI EXPORTNUM(210) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryFullAttributes NTToXboxFileInformation(&nativeNetOpenInfo, Attributes, FileNetworkOpenInformation, sizeof(xboxkrnl::FILE_NETWORK_OPEN_INFORMATION)); if (FAILED(ret)) - EmuWarning("NtQueryFullAttributesFile failed! (0x%.08X)", ret); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtQueryFullAttributesFile failed! (0x%.08X)", ret); RETURN(LOG_PREFIX, ret); } @@ -1281,7 +1281,7 @@ XBSYSAPI EXPORTNUM(211) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryInformationFil free(ntFileInfo); if (FAILED(ret)) - EmuWarning("NtQueryInformationFile failed! (0x%.08X)", ret); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtQueryInformationFile failed! (0x%.08X)", ret); // Prioritize the buffer overflow over real return code, // in case the Xbox program decides to follow the same procedure above @@ -1332,7 +1332,7 @@ XBSYSAPI EXPORTNUM(213) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryMutant /*ReturnLength=*/nullptr); if (ret != STATUS_SUCCESS) - EmuWarning("NtQueryMutant failed! (%s)", NtStatusToString(ret)); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtQueryMutant failed! (%s)", NtStatusToString(ret)); RETURN(LOG_PREFIX, ret); } @@ -1359,7 +1359,7 @@ XBSYSAPI EXPORTNUM(214) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQuerySemaphore /*ReturnLength=*/nullptr); if (ret != STATUS_SUCCESS) - EmuWarning("NtQuerySemaphore failed! (%s)", NtStatusToString(ret)); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtQuerySemaphore failed! (%s)", NtStatusToString(ret)); RETURN(LOG_PREFIX, ret); } @@ -1412,7 +1412,7 @@ XBSYSAPI EXPORTNUM(215) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQuerySymbolicLinkOb } } if (ret != STATUS_SUCCESS) - EmuWarning("NtQuerySymbolicLinkObject failed! (%s)", NtStatusToString(ret)); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtQuerySymbolicLinkObject failed! (%s)", NtStatusToString(ret)); RETURN(LOG_PREFIX, ret); } @@ -1460,7 +1460,7 @@ XBSYSAPI EXPORTNUM(217) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryVirtualMemory if (!Buffer) { - EmuWarning("KNRL: NtQueryVirtualMemory : PMEMORY_BASIC_INFORMATION Buffer is nullptr!\n"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtQueryVirtualMemory : PMEMORY_BASIC_INFORMATION Buffer is nullptr!\n"); LOG_IGNORED(LOG_PREFIX); RETURN(LOG_PREFIX, STATUS_INVALID_PARAMETER); } @@ -1469,18 +1469,18 @@ XBSYSAPI EXPORTNUM(217) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryVirtualMemory if (ret == STATUS_SUCCESS) { - DbgPrintf(" Buffer->AllocationBase = 0x%.08X\n", Buffer->AllocationBase); - DbgPrintf(" Buffer->AllocationProtect = 0x%.08X\n", Buffer->AllocationProtect); - DbgPrintf(" Buffer->BaseAddress = 0x%.08X\n", Buffer->BaseAddress); - DbgPrintf(" Buffer->RegionSize = 0x%.08X\n", Buffer->RegionSize); - DbgPrintf(" Buffer->State = 0x%.08X\n", Buffer->State); - DbgPrintf(" Buffer->Protect = 0x%.08X\n", Buffer->Protect); - DbgPrintf(" Buffer->Type = 0x%.08X\n", Buffer->Type); + 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); } #if 0 if (FAILED(ret)) { - EmuWarning("NtQueryVirtualMemory failed (%s)!", NtStatusToString(ret)); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtQueryVirtualMemory failed (%s)!", NtStatusToString(ret)); // Bugfix for "Forza Motorsport", which iterates over 2 Gb of memory in 64kb chunks, // but fails on this last query. It's not done though, as after this Forza tries to @@ -1499,7 +1499,7 @@ XBSYSAPI EXPORTNUM(217) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryVirtualMemory ret = STATUS_SUCCESS; - DbgPrintf("KRNL: NtQueryVirtualMemory: Applied fix for Forza Motorsport!\n"); + DbgPrintf(LOG_PREFIX, "NtQueryVirtualMemory: Applied fix for Forza Motorsport!\n"); } } #endif @@ -1605,7 +1605,7 @@ XBSYSAPI EXPORTNUM(218) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryVolumeInformat break; default: // For all other types, just do a memcpy and hope for the best! - EmuWarning("NtQueryVolumeInformationFile: Unknown FileInformationClass"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtQueryVolumeInformationFile: Unknown FileInformationClass"); memcpy_s(FileInformation, Length, NativeFileInformation, HostBufferSize); break; } @@ -1614,7 +1614,7 @@ XBSYSAPI EXPORTNUM(218) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtQueryVolumeInformat _aligned_free(NativeFileInformation); if (FAILED(ret)) { - EmuWarning("NtQueryVolumeInformationFile failed! (%s)\n", NtStatusToString(ret)); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtQueryVolumeInformationFile failed! (%s)\n", NtStatusToString(ret)); } RETURN(LOG_PREFIX, ret); @@ -1671,7 +1671,7 @@ XBSYSAPI EXPORTNUM(219) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtReadFile /*Key=*/nullptr); if (FAILED(ret)) { - EmuWarning("NtReadFile Failed! (0x%.08X)", ret); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtReadFile Failed! (0x%.08X)", ret); } RETURN(LOG_PREFIX, ret); @@ -1726,7 +1726,7 @@ XBSYSAPI EXPORTNUM(221) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtReleaseMutant NTSTATUS ret = NtDll::NtReleaseMutant(MutantHandle, PreviousCount); if (FAILED(ret)) - EmuWarning("NtReleaseMutant Failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtReleaseMutant Failed!"); RETURN(LOG_PREFIX, STATUS_SUCCESS); // TODO : RETURN(LOG_PREFIX, ret); } @@ -1753,7 +1753,7 @@ XBSYSAPI EXPORTNUM(222) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtReleaseSemaphore PreviousCount); if (FAILED(ret)) - EmuWarning("NtReleaseSemaphore failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtReleaseSemaphore failed!"); RETURN(LOG_PREFIX, ret); } @@ -1827,7 +1827,7 @@ XBSYSAPI EXPORTNUM(225) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtSetEvent PreviousState); if (FAILED(ret)) - EmuWarning("NtSetEvent Failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtSetEvent Failed!"); RETURN(LOG_PREFIX, ret); } @@ -1970,7 +1970,7 @@ XBSYSAPI EXPORTNUM(229) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtSetTimerEx /*OUT*/PreviousState); if (FAILED(ret)) - EmuWarning("NtSetTimerEx failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtSetTimerEx failed!"); RETURN(LOG_PREFIX, ret); } @@ -2053,7 +2053,7 @@ XBSYSAPI EXPORTNUM(232) xboxkrnl::VOID NTAPI xboxkrnl::NtUserIoApcDispatcher (CompletionRoutine)(dwErrorCode, dwTransferred, lpOverlapped); - DbgPrintf("KRNL: NtUserIoApcDispatcher Completed\n"); + DbgPrintf(LOG_PREFIX, "NtUserIoApcDispatcher Completed\n"); } // ****************************************************************** @@ -2185,7 +2185,7 @@ XBSYSAPI EXPORTNUM(236) xboxkrnl::NTSTATUS NTAPI xboxkrnl::NtWriteFile /*Key=*/nullptr); if (FAILED(ret)) - EmuWarning("NtWriteFile Failed! (0x%.08X)", ret); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NtWriteFile Failed! (0x%.08X)", ret); RETURN(LOG_PREFIX, ret); } diff --git a/src/CxbxKrnl/EmuKrnlOb.cpp b/src/CxbxKrnl/EmuKrnlOb.cpp index 7f46dcf57..3afd9dc6e 100644 --- a/src/CxbxKrnl/EmuKrnlOb.cpp +++ b/src/CxbxKrnl/EmuKrnlOb.cpp @@ -47,7 +47,6 @@ namespace xboxkrnl #include "Logging.h" // For LOG_FUNC() #include "EmuKrnlLogging.h" #include "CxbxKrnl.h" // For CxbxKrnlCleanup -#include "Emu.h" // For EmuWarning() #include "EmuKrnl.h" // For OBJECT_TO_OBJECT_HEADER() #include "EmuFile.h" // For EmuNtSymbolicLinkObject, NtStatusToString(), etc. #include diff --git a/src/CxbxKrnl/EmuKrnlPs.cpp b/src/CxbxKrnl/EmuKrnlPs.cpp index 72013d006..998672c8a 100644 --- a/src/CxbxKrnl/EmuKrnlPs.cpp +++ b/src/CxbxKrnl/EmuKrnlPs.cpp @@ -50,7 +50,7 @@ namespace xboxkrnl #include "Logging.h" // For LOG_FUNC() #include "EmuKrnlLogging.h" #include "CxbxKrnl.h" // For CxbxKrnl_TLS -#include "Emu.h" // For EmuWarning() +#include "Emu.h" // For EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, ) #include "EmuFS.h" // For EmuGenerateFS #include "EmuXTL.h" @@ -160,7 +160,7 @@ static unsigned int WINAPI PCSTProxy if (pfnNotificationRoutine == NULL) continue; - DbgPrintf("KRNL: Calling pfnNotificationRoutine[%d] (0x%.8X)\n", g_iThreadNotificationCount, pfnNotificationRoutine); + DbgPrintf(LOG_PREFIX, "Calling pfnNotificationRoutine[%d] (0x%.8X)\n", g_iThreadNotificationCount, pfnNotificationRoutine); pfnNotificationRoutine(TRUE); } @@ -188,7 +188,7 @@ static unsigned int WINAPI PCSTProxy } __except (EmuException(GetExceptionInformation())) { - EmuWarning("Problem with ExceptionFilter!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Problem with ExceptionFilter!"); } callComplete: @@ -214,7 +214,7 @@ void PspSystemThreadStartup __except (EmuException(GetExceptionInformation())) // TODO : Call PspUnhandledExceptionInSystemThread(GetExceptionInformation()) { - EmuWarning("Problem with ExceptionFilter!"); // TODO : Disable? + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Problem with ExceptionFilter!"); // TODO : Disable? } xboxkrnl::PsTerminateSystemThread(STATUS_SUCCESS); @@ -309,7 +309,7 @@ XBSYSAPI EXPORTNUM(255) xboxkrnl::NTSTATUS NTAPI xboxkrnl::PsCreateSystemThreadE HANDLE hStartedEvent = CreateEvent(NULL, FALSE, FALSE, TEXT("PCSTProxyEvent")); if (hStartedEvent == NULL) { std::string errorMessage = CxbxGetLastErrorString("PsCreateSystemThreadEx could not create PCSTProxyEvent"); - CxbxKrnlCleanup(errorMessage.c_str()); + CxbxKrnlCleanup(LOG_PREFIX, errorMessage.c_str()); } // PCSTProxy is responsible for cleaning up this pointer @@ -327,18 +327,18 @@ XBSYSAPI EXPORTNUM(255) xboxkrnl::NTSTATUS NTAPI xboxkrnl::PsCreateSystemThreadE // Give the thread chance to start Sleep(100); - EmuWarning("KRNL: Waiting for Xbox proxy thread to start...\n"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "KRNL: Waiting for Xbox proxy thread to start...\n"); while (bWait) { dwThreadWait = WaitForSingleObject(hStartedEvent, 300); switch (dwThreadWait) { case WAIT_TIMEOUT: { // The time-out interval elapsed, and the object's state is nonsignaled. - EmuWarning("KRNL: Timeout while waiting for Xbox proxy thread to start...\n"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "KRNL: Timeout while waiting for Xbox proxy thread to start...\n"); bWait = false; break; } case WAIT_OBJECT_0: { // The state of the specified object is signaled. - DbgPrintf("KRNL: Xbox proxy thread is started.\n"); + DbgPrintf(LOG_PREFIX, "Xbox proxy thread is started.\n"); bWait = false; break; } @@ -347,7 +347,7 @@ XBSYSAPI EXPORTNUM(255) xboxkrnl::NTSTATUS NTAPI xboxkrnl::PsCreateSystemThreadE bWait = false; std::string ErrorStr = CxbxGetLastErrorString("KRNL: While waiting for Xbox proxy thread to start"); - EmuWarning("%s\n", ErrorStr.c_str()); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "%s\n", ErrorStr.c_str()); break; } } @@ -358,7 +358,7 @@ XBSYSAPI EXPORTNUM(255) xboxkrnl::NTSTATUS NTAPI xboxkrnl::PsCreateSystemThreadE hStartedEvent = NULL; // Log ThreadID identical to how GetCurrentThreadID() is rendered : - EmuWarning("KRNL: Created Xbox proxy thread. Handle : 0x%X, ThreadId : [0x%.4X]\n", *ThreadHandle, dwThreadId); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "KRNL: Created Xbox proxy thread. Handle : 0x%X, ThreadId : [0x%.4X]\n", *ThreadHandle, dwThreadId); CxbxKrnlRegisterThread(*ThreadHandle); @@ -408,7 +408,7 @@ XBSYSAPI EXPORTNUM(257) xboxkrnl::NTSTATUS NTAPI xboxkrnl::PsSetCreateThreadNoti // I honestly don't expect this to happen, but if it does... if (g_iThreadNotificationCount >= PSP_MAX_CREATE_THREAD_NOTIFY) - CxbxKrnlCleanup("Too many thread notification routines installed\n"); + CxbxKrnlCleanup(LOG_PREFIX, "Too many thread notification routines installed\n"); // Find an empty spot in the thread notification array for (int i = 0; i < PSP_MAX_CREATE_THREAD_NOTIFY; i++) @@ -451,7 +451,7 @@ XBSYSAPI EXPORTNUM(258) xboxkrnl::VOID NTAPI xboxkrnl::PsTerminateSystemThread if (pfnNotificationRoutine == NULL) continue; - DbgPrintf("KRNL: Calling pfnNotificationRoutine[%d] (0x%.8X)\n", g_iThreadNotificationCount, pfnNotificationRoutine); + DbgPrintf(LOG_PREFIX, "Calling pfnNotificationRoutine[%d] (0x%.8X)\n", g_iThreadNotificationCount, pfnNotificationRoutine); pfnNotificationRoutine(FALSE); } diff --git a/src/CxbxKrnl/EmuKrnlRtl.cpp b/src/CxbxKrnl/EmuKrnlRtl.cpp index 16a94ace2..9ba011ad6 100644 --- a/src/CxbxKrnl/EmuKrnlRtl.cpp +++ b/src/CxbxKrnl/EmuKrnlRtl.cpp @@ -55,7 +55,7 @@ namespace NtDll }; #include "CxbxKrnl.h" // For CxbxKrnlCleanup() -#include "Emu.h" // For EmuWarning() +#include "Emu.h" // For EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, ) #include #ifdef _WIN32 @@ -80,7 +80,7 @@ static void add_critical_section( critical_sections[xbox_crit_section] = host_crit_section; } else { - DbgPrintf("Critical Section key %p already exists\n", xbox_crit_section); + DbgPrintf(LOG_PREFIX, "Critical Section key %p already exists\n", xbox_crit_section); } } @@ -303,7 +303,7 @@ XBSYSAPI EXPORTNUM(264) xboxkrnl::VOID NTAPI xboxkrnl::RtlAssert LOG_FUNC_ARG(Message) LOG_FUNC_END; - CxbxPopupMessage(CxbxMsgDlgIcon_Warn, "RtlAssert() raised by emulated program - consult Debug log"); + CxbxPopupMessage(LOG_PREFIX, LOG_LEVEL::WARNING, CxbxMsgDlgIcon_Warn, "RtlAssert() raised by emulated program - consult Debug log"); } // ****************************************************************** @@ -742,7 +742,7 @@ XBSYSAPI EXPORTNUM(277) xboxkrnl::VOID NTAPI xboxkrnl::RtlEnterCriticalSection ); if(!NT_SUCCESS(result)) { - CxbxKrnlCleanup("Waiting for event of a critical section returned %lx.", result); + CxbxKrnlCleanup(LOG_PREFIX, "Waiting for event of a critical section returned %lx.", result); }; CriticalSection->OwningThread = thread; CriticalSection->RecursionCount = 1; @@ -1473,7 +1473,7 @@ XBSYSAPI EXPORTNUM(301) xboxkrnl::ULONG NTAPI xboxkrnl::RtlNtStatusToDosError return LOWORD(Status); no_mapping: - DbgPrintf("no mapping for %08x\n", Status); + DbgPrintf(LOG_PREFIX, "no mapping for %08x\n", Status); ret = ERROR_MR_MID_NOT_FOUND; */ RETURN(LOG_PREFIX, ret); @@ -2157,6 +2157,6 @@ XBSYSAPI EXPORTNUM(352) xboxkrnl::VOID NTAPI xboxkrnl::RtlRip LOG_FUNC_ARG(Message) LOG_FUNC_END; - EmuWarning("RtlRip@%s:\n\nASSERT FAILED:\n%s\n\nDescription:\n%s", + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "RtlRip@%s:\n\nASSERT FAILED:\n%s\n\nDescription:\n%s", ApiName, Expression, Message); } diff --git a/src/CxbxKrnl/EmuKrnlXe.cpp b/src/CxbxKrnl/EmuKrnlXe.cpp index 7a4a0f887..c9d6a5043 100644 --- a/src/CxbxKrnl/EmuKrnlXe.cpp +++ b/src/CxbxKrnl/EmuKrnlXe.cpp @@ -47,7 +47,6 @@ namespace xboxkrnl #include "CxbxKrnl.h" // For CxbxKrnl_Xbe #include "Logging.h" // For LOG_FUNC() #include "EmuKrnlLogging.h" -#include "Emu.h" // For EmuWarning() #include "VMManager.h" // ****************************************************************** diff --git a/src/CxbxKrnl/EmuRsa.cpp b/src/CxbxKrnl/EmuRsa.cpp index a118763db..83dacb26e 100644 --- a/src/CxbxKrnl/EmuRsa.cpp +++ b/src/CxbxKrnl/EmuRsa.cpp @@ -36,6 +36,8 @@ // This rsa implementation is directly borrowed from the xbedump tool of XQEMU (GPLv2 license) // https://github.com/xqemu/xbedump +#define LOG_PREFIX CXBXR_MODULE::RSA + #include "EmuRsa.h" #include "Emu.h" // For EmuWarning #include @@ -225,7 +227,7 @@ giant newgiant(int numshorts) giant thegiant; if (numshorts > MAX_SHORTS) { - EmuWarning("Requested giant too big."); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Requested giant too big."); } if (numshorts <= 0) numshorts = MAX_SHORTS; diff --git a/src/CxbxKrnl/EmuX86.cpp b/src/CxbxKrnl/EmuX86.cpp index 2eddcfcba..0174abfaa 100644 --- a/src/CxbxKrnl/EmuX86.cpp +++ b/src/CxbxKrnl/EmuX86.cpp @@ -95,7 +95,7 @@ uint32_t EmuX86_IORead(xbaddr addr, int size) return value; } - EmuWarning("EmuX86_IORead(0x%08X, %d) [Unhandled]", addr, size); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuX86_IORead(0x%08X, %d) [Unhandled]", addr, size); return 0; } @@ -106,7 +106,7 @@ void EmuX86_IOWrite(xbaddr addr, uint32_t value, int size) return; } - EmuWarning("EmuX86_IOWrite(0x%08X, 0x%04X, %d) [Unhandled]", addr, value, size); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuX86_IOWrite(0x%08X, 0x%04X, %d) [Unhandled]", addr, value, size); } // @@ -158,11 +158,11 @@ uint32_t EmuFlash_Read32(xbaddr addr) // TODO : Move to EmuFlash.cpp r = 0x90; // Luke's hardware revision 1.6 Xbox returns this (also since XboxKrnlVersion is set to 5838) break; default: - EmuWarning("Read32 FLASH_ROM (0x%.8X) [Unknown address]", addr); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Read32 FLASH_ROM (0x%.8X) [Unknown address]", addr); return -1; } - DbgPrintf("X86 : Read32 FLASH_ROM (0x%.8X) = 0x%.8X [HANDLED]\n", addr, r); + DbgPrintf(LOG_PREFIX, "Read32 FLASH_ROM (0x%.8X) = 0x%.8X [HANDLED]\n", addr, r); return r; } @@ -173,7 +173,7 @@ uint32_t EmuFlash_Read32(xbaddr addr) // TODO : Move to EmuFlash.cpp uint32_t EmuX86_Read(xbaddr addr, int size) { if ((addr & (size - 1)) != 0) { - EmuWarning("EmuX86_Read(0x%08X, %d) [Unaligned unimplemented]", addr, size); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuX86_Read(0x%08X, %d) [Unaligned unimplemented]", addr, size); // LOG_UNIMPLEMENTED(); return 0; } @@ -192,14 +192,14 @@ uint32_t EmuX86_Read(xbaddr addr, int size) } if (g_bEmuException) { - EmuWarning("EmuX86_Read(0x%08X, %d) [Unknown address]", addr, size); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuX86_Read(0x%08X, %d) [Unknown address]", addr, size); value = 0; } else { // Outside EmuException, pass the memory-access through to normal memory : value = EmuX86_Mem_Read(addr, size); } - DbgPrintf("X86 : Read(0x%08X, %d) = 0x%08X\n", addr, size, value); + DbgPrintf(LOG_PREFIX, "Read(0x%08X, %d) = 0x%08X\n", addr, size, value); } return value; @@ -208,13 +208,13 @@ uint32_t EmuX86_Read(xbaddr addr, int size) void EmuX86_Write(xbaddr addr, uint32_t value, int size) { if ((addr & (size - 1)) != 0) { - EmuWarning("EmuX86_Write(0x%08X, 0x%08X, %d) [Unaligned unimplemented]", addr, value, size); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuX86_Write(0x%08X, 0x%08X, %d) [Unaligned unimplemented]", addr, value, size); // LOG_UNIMPLEMENTED(); return; } if (addr >= XBOX_FLASH_ROM_BASE) { // 0xFFF00000 - 0xFFFFFFF - EmuWarning("EmuX86_Write(0x%08X, 0x%08X) [FLASH_ROM]", addr, value); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuX86_Write(0x%08X, 0x%08X) [FLASH_ROM]", addr, value); return; } @@ -224,12 +224,12 @@ void EmuX86_Write(xbaddr addr, uint32_t value, int size) } if (g_bEmuException) { - EmuWarning("EmuX86_Write(0x%08X, 0x%08X) [Unknown address]", addr, value); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuX86_Write(0x%08X, 0x%08X) [Unknown address]", addr, value); return; } // Outside EmuException, pass the memory-access through to normal memory : - DbgPrintf("X86 : Write(0x%.8X, 0x%.8X, %d)\n", addr, value, size); + DbgPrintf(LOG_PREFIX, "Write(0x%.8X, 0x%.8X, %d)\n", addr, value, size); EmuX86_Mem_Write(addr, value, size); } @@ -465,7 +465,7 @@ bool EmuX86_Operand_Addr_ForReadWrite(const LPEXCEPTION_POINTERS e, const _DInst case O_IMM: case O_IMM1: case O_IMM2: - EmuWarning("Refused operand write-access to immedate value address!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Refused operand write-access to immedate value address!"); return false; } @@ -1050,7 +1050,7 @@ int EmuX86_OpcodeSize(uint8_t *Eip) if (EmuX86_DecodeOpcode((uint8_t*)Eip, info)) return info.size; - EmuWarning("Error decoding opcode size at 0x%.8X", Eip); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Error decoding opcode size at 0x%.8X", Eip); return 1; } @@ -1063,7 +1063,7 @@ bool EmuX86_DecodeException(LPEXCEPTION_POINTERS e) // that case may be logged, but it shouldn't fail the opcode handler. _DInst info; if (!EmuX86_DecodeOpcode((uint8_t*)e->ContextRecord->Eip, OUT info)) { - EmuWarning("Error decoding opcode at 0x%08X", e->ContextRecord->Eip); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Error decoding opcode at 0x%08X", e->ContextRecord->Eip); return false; } @@ -1122,7 +1122,7 @@ bool EmuX86_DecodeException(LPEXCEPTION_POINTERS e) // Some titles attempt to manually set the TSC via this instruction // This needs fixing eventually, but should be acceptible to ignore for now! // Chase: Hollywood Stunt Driver hits this - EmuWarning("WRMSR instruction ignored"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "WRMSR instruction ignored"); break; case I_CLI: { // Disable all interrupts @@ -1135,7 +1135,7 @@ bool EmuX86_DecodeException(LPEXCEPTION_POINTERS e) break; } default: - EmuWarning("Unhandled instruction : %u", info.opcode); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unhandled instruction : %u", info.opcode); e->ContextRecord->Eip += info.size; return false; } @@ -1146,14 +1146,14 @@ bool EmuX86_DecodeException(LPEXCEPTION_POINTERS e) return true; opcode_error: - EmuWarning("0x%08X: Error while handling instruction %u", e->ContextRecord->Eip, info.opcode); // TODO : format decodedInstructions[0] + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "0x%08X: Error while handling instruction %u", e->ContextRecord->Eip, info.opcode); // TODO : format decodedInstructions[0] e->ContextRecord->Eip += info.size; return false; } void EmuX86_Init() { - DbgPrintf("X86 : Initializing distorm version %d\n", distorm_version()); + DbgPrintf(LOG_PREFIX, "Initializing distorm version %d\n", distorm_version()); AddVectoredExceptionHandler(/*FirstHandler=*/ULONG(true), lleException); diff --git a/src/CxbxKrnl/EmuXG.cpp b/src/CxbxKrnl/EmuXG.cpp index 0c0822eaa..4f8fbc4e5 100644 --- a/src/CxbxKrnl/EmuXG.cpp +++ b/src/CxbxKrnl/EmuXG.cpp @@ -95,7 +95,7 @@ VOID WINAPI XTL::EMUPATCH(XGSwizzleRect) else { if(pPoint != NULL && (pPoint->x != 0 || pPoint->y != 0)) - CxbxKrnlCleanup("Temporarily unsupported swizzle (very easy fix)"); + CxbxKrnlCleanup(LOG_PREFIX, "Temporarily unsupported swizzle (very easy fix)"); DWORD dwMaxY = Height; DWORD dwChunkSize = Width; @@ -163,7 +163,7 @@ VOID WINAPI XTL::EMUPATCH(XGSwizzleBox) else { if(pPoint != NULL && (pPoint->u != 0 || pPoint->v != 0 || pPoint->w != 0)) - CxbxKrnlCleanup("Temporarily unsupported swizzle (very easy fix)"); + CxbxKrnlCleanup(LOG_PREFIX, "Temporarily unsupported swizzle (very easy fix)"); DWORD dwMaxY = Height; DWORD dwMaxZ = Depth; @@ -249,10 +249,10 @@ VOID WINAPI XTL::EMUPATCH(XGSetTextureHeader) LOG_FUNC_END; /*if( Data != 0 ) - CxbxKrnlCleanup( "Data != 0 (XGSetTextureHeader)" ); + CxbxKrnlCleanup(LOG_PREFIX, "Data != 0 (XGSetTextureHeader)" ); if( Pitch != 0 ) - CxbxKrnlCleanup( "Pitch != 0 (XGSetTextureHeader)" );*/ + CxbxKrnlCleanup(LOG_PREFIX, "Pitch != 0 (XGSetTextureHeader)" );*/ pTexture->Common = X_D3DCOMMON_TYPE_TEXTURE + 1; // Set refcount to 1 pTexture->Data = Data; diff --git a/src/CxbxKrnl/EmuXapi.cpp b/src/CxbxKrnl/EmuXapi.cpp index 2abafd38a..e884e4a3c 100644 --- a/src/CxbxKrnl/EmuXapi.cpp +++ b/src/CxbxKrnl/EmuXapi.cpp @@ -52,10 +52,10 @@ namespace xboxkrnl #include "EmuFile.h" #include "EmuFS.h" #include "EmuXTL.h" -#include "EmuShared.h" +#include "EmuShared.h" #include "../Common/Win32/XBPortMapping.h" -#include "HLEIntercept.h" -#include "CxbxVSBC/CxbxVSBC.h" +#include "HLEIntercept.h" +#include "CxbxVSBC/CxbxVSBC.h" #include "Windef.h" #include @@ -65,107 +65,107 @@ extern XInputSetStateStatus g_pXInputSetStateStatus[XINPUT_SETSTATE_SLOTS] = {0} // XInputOpen handles extern HANDLE g_hInputHandle[XINPUT_HANDLE_SLOTS] = {0}; -bool g_bXInputOpenCalled = false; +bool g_bXInputOpenCalled = false; bool g_bCxbxVSBCLoaded = false; -HINSTANCE g_module; -typedef int (FAR WINAPI *PFARPROC1)(int); -typedef int (FAR WINAPI *PFARPROC2)(UCHAR*); -typedef int (NEAR WINAPI *PNEARPROC1)(int); -typedef int (NEAR WINAPI *PNEARPROC2)(UCHAR*); +HINSTANCE g_module; +typedef int (FAR WINAPI *PFARPROC1)(int); +typedef int (FAR WINAPI *PFARPROC2)(UCHAR*); +typedef int (NEAR WINAPI *PNEARPROC1)(int); +typedef int (NEAR WINAPI *PNEARPROC2)(UCHAR*); typedef int (WINAPI *PPROC)(); - -PFARPROC2 fnCxbxVSBCSetState; -PFARPROC2 fnCxbxVSBCGetState; -PFARPROC1 fnCxbxVSBCOpen; -//typedef DWORD(*fnCxbxVSBCOpen)(HWND); -//typedef DWORD(*fnCxbxVSBCSetState)(UCHAR *); -//typedef DWORD(*fnCxbxVSBCGetState)(UCHAR *); + +PFARPROC2 fnCxbxVSBCSetState; +PFARPROC2 fnCxbxVSBCGetState; +PFARPROC1 fnCxbxVSBCOpen; +//typedef DWORD(*fnCxbxVSBCOpen)(HWND); +//typedef DWORD(*fnCxbxVSBCSetState)(UCHAR *); +//typedef DWORD(*fnCxbxVSBCGetState)(UCHAR *); XTL::PXPP_DEVICE_TYPE gDeviceType_Gamepad = nullptr; XTL::X_POLLING_PARAMETERS_HANDLE g_pph[4]; -XTL::X_XINPUT_POLLING_PARAMETERS g_pp[4]; +XTL::X_XINPUT_POLLING_PARAMETERS g_pp[4]; //for host connected gamepad -DWORD total_xinput_gamepad = 0; -//global bridge for xbox controller to host, 4 elements for 4 ports. -XTL::X_CONTROLLER_HOST_BRIDGE g_XboxControllerHostBridge[4] = {}; -//global xbox xinput device info from interpreting device table. +DWORD total_xinput_gamepad = 0; +//global bridge for xbox controller to host, 4 elements for 4 ports. +XTL::X_CONTROLLER_HOST_BRIDGE g_XboxControllerHostBridge[4] = {}; +//global xbox xinput device info from interpreting device table. std::vector g_XboxInputDeviceInfo; - - - -//look for xbox Device info from global info vector, and return the found index. return -1 for not found. -int FindDeviceInfoIndexByXboxType(UCHAR ucType) -{ - size_t i; + + + +//look for xbox Device info from global info vector, and return the found index. return -1 for not found. +int FindDeviceInfoIndexByXboxType(UCHAR ucType) +{ + size_t i; for (i = 0; i < g_XboxInputDeviceInfo.size(); i++) { if (g_XboxInputDeviceInfo[i].ucType == ucType) { return i; } - } + } return -1; -} - -//look for xbox Device info from global info vector, and return the found index. return -1 for not found. -int FindDeviceInfoIndexByDeviceType(XTL::PXPP_DEVICE_TYPE DeviceType) -{ - size_t i; +} + +//look for xbox Device info from global info vector, and return the found index. return -1 for not found. +int FindDeviceInfoIndexByDeviceType(XTL::PXPP_DEVICE_TYPE DeviceType) +{ + size_t i; for (i = 0; i < g_XboxInputDeviceInfo.size(); i++) { if (g_XboxInputDeviceInfo[i].DeviceType == DeviceType) { return i; } - } + } return -1; -} - -//init XboxControllerHostBridge's content, also put interpreted data from device table to it. -//this is called in the end of SetupXboxDeviceTypes(), later we'll move this code to accept user configuration. -void InitXboxControllerHostBridge(void) +} + +//init XboxControllerHostBridge's content, also put interpreted data from device table to it. +//this is called in the end of SetupXboxDeviceTypes(), later we'll move this code to accept user configuration. +void InitXboxControllerHostBridge(void) { - //load host type and port configuration from settings. - Settings::s_controller_port ControllerPortMap; - g_EmuShared->GetControllerPortSettings(&ControllerPortMap); - XBPortMappingSet(ControllerPortMap); + //load host type and port configuration from settings. + Settings::s_controller_port ControllerPortMap; + g_EmuShared->GetControllerPortSettings(&ControllerPortMap); + XBPortMappingSet(ControllerPortMap); total_xinput_gamepad = XTL::XInputGamepad_Connected(); - - int port; - for (port = 0; port < 4; port++) { - g_XboxControllerHostBridge[port].dwHostType = GetXboxPortMapHostType(port); - g_XboxControllerHostBridge[port].dwHostPort = GetXboxPortMapHostPort(port); - g_XboxControllerHostBridge[port].XboxDeviceInfo.ucType = X_XINPUT_DEVTYPE_GAMEPAD; - switch (GetXboxPortMapHostType(port)) { - case X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_XINPUT: - //disconnect to host if the host port of xinput exceeds the total xinput controller connected to host. - if (g_XboxControllerHostBridge[port].dwHostPort >= total_xinput_gamepad) { - g_XboxControllerHostBridge[port].dwHostType = X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_NOTCONNECT; - printf("InitXboxControllerHostBridge: Host XInput port greater then total xinut controller connected. disconnect xbox port from host!\n"); - } - break; - case X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_DINPUT: - break; - case X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_VIRTUAL_SBC: - g_XboxControllerHostBridge[port].XboxDeviceInfo.ucType = X_XINPUT_DEVTYPE_STEELBATALION; - break; - default: - break; - } - g_XboxControllerHostBridge[port].dwXboxPort = port; - //xbox device handle set to 0 before being open. - g_XboxControllerHostBridge[port].hXboxDevice = 0; - int index; - //find corresponding XboxDeviceInfo - index=FindDeviceInfoIndexByXboxType(g_XboxControllerHostBridge[port].XboxDeviceInfo.ucType); - if (index == -1) { - printf("XboxControllerHostBridge XboxDeviceInfo.ucType: %d not found in global XboxInputDeviceInfo vector!\n", g_XboxControllerHostBridge[port].XboxDeviceInfo.ucType); - } - //copy XboxDeviceInfo from the global vector. - g_XboxControllerHostBridge[port].XboxDeviceInfo.ucSubType = g_XboxInputDeviceInfo[index].ucSubType; - g_XboxControllerHostBridge[port].XboxDeviceInfo.DeviceType = g_XboxInputDeviceInfo[index].DeviceType; - g_XboxControllerHostBridge[port].XboxDeviceInfo.ucInputStateSize = g_XboxInputDeviceInfo[index].ucInputStateSize; - g_XboxControllerHostBridge[port].XboxDeviceInfo.ucFeedbackSize = g_XboxInputDeviceInfo[index].ucFeedbackSize; - //these two members are not used yet. - g_XboxControllerHostBridge[port].pXboxState = 0; - g_XboxControllerHostBridge[port].pXboxFeedbackHeader = 0; + + int port; + for (port = 0; port < 4; port++) { + g_XboxControllerHostBridge[port].dwHostType = GetXboxPortMapHostType(port); + g_XboxControllerHostBridge[port].dwHostPort = GetXboxPortMapHostPort(port); + g_XboxControllerHostBridge[port].XboxDeviceInfo.ucType = X_XINPUT_DEVTYPE_GAMEPAD; + switch (GetXboxPortMapHostType(port)) { + case X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_XINPUT: + //disconnect to host if the host port of xinput exceeds the total xinput controller connected to host. + if (g_XboxControllerHostBridge[port].dwHostPort >= total_xinput_gamepad) { + g_XboxControllerHostBridge[port].dwHostType = X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_NOTCONNECT; + printf("InitXboxControllerHostBridge: Host XInput port greater then total xinut controller connected. disconnect xbox port from host!\n"); + } + break; + case X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_DINPUT: + break; + case X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_VIRTUAL_SBC: + g_XboxControllerHostBridge[port].XboxDeviceInfo.ucType = X_XINPUT_DEVTYPE_STEELBATALION; + break; + default: + break; + } + g_XboxControllerHostBridge[port].dwXboxPort = port; + //xbox device handle set to 0 before being open. + g_XboxControllerHostBridge[port].hXboxDevice = 0; + int index; + //find corresponding XboxDeviceInfo + index=FindDeviceInfoIndexByXboxType(g_XboxControllerHostBridge[port].XboxDeviceInfo.ucType); + if (index == -1) { + printf("XboxControllerHostBridge XboxDeviceInfo.ucType: %d not found in global XboxInputDeviceInfo vector!\n", g_XboxControllerHostBridge[port].XboxDeviceInfo.ucType); + } + //copy XboxDeviceInfo from the global vector. + g_XboxControllerHostBridge[port].XboxDeviceInfo.ucSubType = g_XboxInputDeviceInfo[index].ucSubType; + g_XboxControllerHostBridge[port].XboxDeviceInfo.DeviceType = g_XboxInputDeviceInfo[index].DeviceType; + g_XboxControllerHostBridge[port].XboxDeviceInfo.ucInputStateSize = g_XboxInputDeviceInfo[index].ucInputStateSize; + g_XboxControllerHostBridge[port].XboxDeviceInfo.ucFeedbackSize = g_XboxInputDeviceInfo[index].ucFeedbackSize; + //these two members are not used yet. + g_XboxControllerHostBridge[port].pXboxState = 0; + g_XboxControllerHostBridge[port].pXboxFeedbackHeader = 0; } } void SetupXboxDeviceTypes() @@ -189,7 +189,7 @@ void SetupXboxDeviceTypes() // Sanity check: Where all these device offsets within Xbox memory if ((deviceTableStartOffset >= g_SystemMaxMemory) || (deviceTableEndOffset >= g_SystemMaxMemory)) { - CxbxKrnlCleanup("XAPI DeviceTable Location is outside of Xbox Memory range"); + CxbxKrnlCleanup(LOG_PREFIX, "DeviceTable Location is outside of Xbox Memory range"); } // Iterate through the table until we find gamepad @@ -203,33 +203,33 @@ void SetupXboxDeviceTypes() printf("----------------------------------------\n"); printf("DeviceTable[%u]->ucType = %d\n", i, deviceTable[i]->ucType); printf("DeviceTable[%u]->XppType = 0x%08X (", i, deviceTable[i]->XppType); - - XTL::X_XINPUT_DEVICE_INFO CurrentInfo = {}; - CurrentInfo.ucType = deviceTable[i]->ucType; - CurrentInfo.DeviceType = deviceTable[i]->XppType; - if (deviceTable[i]->pInputStateDesc!=0) { - CurrentInfo.ucInputStateSize = deviceTable[i]->pInputStateDesc->ucSize; - } - if(deviceTable[i]->pFeedbackDesc!=0){ - CurrentInfo.ucFeedbackSize = deviceTable[i]->pFeedbackDesc->ucSize; - } - + + XTL::X_XINPUT_DEVICE_INFO CurrentInfo = {}; + CurrentInfo.ucType = deviceTable[i]->ucType; + CurrentInfo.DeviceType = deviceTable[i]->XppType; + if (deviceTable[i]->pInputStateDesc!=0) { + CurrentInfo.ucInputStateSize = deviceTable[i]->pInputStateDesc->ucSize; + } + if(deviceTable[i]->pFeedbackDesc!=0){ + CurrentInfo.ucFeedbackSize = deviceTable[i]->pFeedbackDesc->ucSize; + } + switch (deviceTable[i]->ucType) { case X_XINPUT_DEVTYPE_GAMEPAD: - gDeviceType_Gamepad = deviceTable[i]->XppType; + gDeviceType_Gamepad = deviceTable[i]->XppType; CurrentInfo.ucSubType = X_XINPUT_DEVSUBTYPE_GC_GAMEPAD; printf("XDEVICE_TYPE_GAMEPAD)\n"); - break; + break; case X_XINPUT_DEVTYPE_STEELBATALION: - printf("XDEVICE_TYPE_STEELBATALION)\n"); + printf("XDEVICE_TYPE_STEELBATALION)\n"); CurrentInfo.ucSubType = X_XINPUT_DEVSUBTYPE_GC_GAMEPAD_ALT; break; default: - printf("Unknown device type)\n"); + printf("Unknown device type)\n"); continue; - } - - //store the DeviceInfo in global vector. + } + + //store the DeviceInfo in global vector. g_XboxInputDeviceInfo.push_back(CurrentInfo); } } else { @@ -239,29 +239,29 @@ void SetupXboxDeviceTypes() void* XInputOpenAddr = (void*)g_SymbolAddresses["XInputOpen"]; if (XInputOpenAddr != nullptr) { printf("XAPI: Deriving XDEVICE_TYPE_GAMEPAD from XInputOpen (0x%08X)\n", XInputOpenAddr); - gDeviceType_Gamepad = *(XTL::PXPP_DEVICE_TYPE*)((uint32_t)XInputOpenAddr + 0x0B); - - //only have one GAMEPAD device type. setup global DeviceInfo vector accordingly. - XTL::X_XINPUT_DEVICE_INFO CurrentInfo = {}; - CurrentInfo.ucType = X_XINPUT_DEVTYPE_GAMEPAD; - CurrentInfo.ucSubType = X_XINPUT_DEVSUBTYPE_GC_GAMEPAD; - CurrentInfo.DeviceType = gDeviceType_Gamepad; - CurrentInfo.ucInputStateSize = sizeof(XTL::X_XINPUT_GAMEPAD); - CurrentInfo.ucFeedbackSize = sizeof(XTL::X_XINPUT_RUMBLE); - //store the DeviceInfo in global vector. + gDeviceType_Gamepad = *(XTL::PXPP_DEVICE_TYPE*)((uint32_t)XInputOpenAddr + 0x0B); + + //only have one GAMEPAD device type. setup global DeviceInfo vector accordingly. + XTL::X_XINPUT_DEVICE_INFO CurrentInfo = {}; + CurrentInfo.ucType = X_XINPUT_DEVTYPE_GAMEPAD; + CurrentInfo.ucSubType = X_XINPUT_DEVSUBTYPE_GC_GAMEPAD; + CurrentInfo.DeviceType = gDeviceType_Gamepad; + CurrentInfo.ucInputStateSize = sizeof(XTL::X_XINPUT_GAMEPAD); + CurrentInfo.ucFeedbackSize = sizeof(XTL::X_XINPUT_RUMBLE); + //store the DeviceInfo in global vector. g_XboxInputDeviceInfo.push_back(CurrentInfo); } } if (gDeviceType_Gamepad == nullptr) { - EmuWarning("XAPI: XDEVICE_TYPE_GAMEPAD was not found"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "XDEVICE_TYPE_GAMEPAD was not found"); return; } printf("XAPI: XDEVICE_TYPE_GAMEPAD Found at 0x%08X\n", gDeviceType_Gamepad); } } - + // ****************************************************************** // * patch: XInitDevices // ****************************************************************** @@ -276,7 +276,7 @@ VOID WINAPI XTL::EMUPATCH(XInitDevices) LOG_FUNC_BEGIN(LOG_PREFIX) LOG_FUNC_ARG(dwPreallocTypeCount) LOG_FUNC_ARG((DWORD)PreallocTypes) - LOG_FUNC_END; + LOG_FUNC_END; /* for(int v=0;vwszTitleName, sizeof(tAsciiTitle)); if (_strnicmp(tAsciiTitle, "Jet Set Radio", 13) == 0) { - CxbxPopupMessage(CxbxMsgDlgIcon_Info, "Detected JSRF by name, not title ID, please report that [%08X] should be added to the list", g_pCertificate->dwTitleId); + CxbxPopupMessage(LOG_PREFIX, LOG_LEVEL::INFO, CxbxMsgDlgIcon_Info, "Detected JSRF by name, not title ID, please report that [%08X] should be added to the list", g_pCertificate->dwTitleId); result = true; } } if (result) { - EmuWarning("Applying JSRF Hack"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Applying JSRF Hack"); } detected = true; @@ -371,7 +371,7 @@ bool TitleIsLegoSW() } if (result) { - EmuWarning("Applying Lego Star Wars Hack"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Applying Lego Star Wars Hack"); } detected = true; @@ -400,25 +400,25 @@ DWORD WINAPI XTL::EMUPATCH(XGetDevices) DeviceType->ChangeConnected = 0; DeviceType->PreviousConnected = DeviceType->CurrentConnected; - int index = FindDeviceInfoIndexByDeviceType(DeviceType); - int port; - if (DeviceType->CurrentConnected == 0) { - for (port = 0; port < 4; port++) { - //if the host controller is connected and the xbox DeviceType matches. set the CurrentConnected flag. - if (g_XboxControllerHostBridge[port].XboxDeviceInfo.DeviceType == DeviceType && g_XboxControllerHostBridge[port].dwHostType>0) { - DeviceType->CurrentConnected |= 1 << port; - } - } - } - //the ChangeConnected flag must be set here together with the CurrentConnected flag. + int index = FindDeviceInfoIndexByDeviceType(DeviceType); + int port; + if (DeviceType->CurrentConnected == 0) { + for (port = 0; port < 4; port++) { + //if the host controller is connected and the xbox DeviceType matches. set the CurrentConnected flag. + if (g_XboxControllerHostBridge[port].XboxDeviceInfo.DeviceType == DeviceType && g_XboxControllerHostBridge[port].dwHostType>0) { + DeviceType->CurrentConnected |= 1 << port; + } + } + } + //the ChangeConnected flag must be set here together with the CurrentConnected flag. DeviceType->ChangeConnected = DeviceType->CurrentConnected; - + // JSRF Hack: Don't set the ChangeConnected flag. Without this, JSRF hard crashes // TODO: Why is this still needed? if (DeviceType == gDeviceType_Gamepad && TitleIsJSRF()) { DeviceType->ChangeConnected = 0; } - ret = DeviceType->CurrentConnected; + ret = DeviceType->CurrentConnected; xboxkrnl::KfLowerIrql(oldIrql); @@ -449,20 +449,20 @@ BOOL WINAPI XTL::EMUPATCH(XGetDeviceChanges) BOOL ret = FALSE; - // If this device type was not previously detected, connect one (or more) - // some titles call XGetDevices first, and the CurrentConnected and ChangeConnected flags are set there. - // note that certain titles such as Otogi need the ChangeConnected to be set to 1 always to enable the input. - int port; - if (DeviceType->CurrentConnected == 0) { - for (port = 0; port < 4; port++) { - //if the host controller is connected and the xbox DeviceType matches. set the CurrentConnected flag. - if (g_XboxControllerHostBridge[port].XboxDeviceInfo.DeviceType == DeviceType && g_XboxControllerHostBridge[port].dwHostType>0) { - DeviceType->CurrentConnected |= 1 << port; - } - } - DeviceType->ChangeConnected = DeviceType->CurrentConnected; + // If this device type was not previously detected, connect one (or more) + // some titles call XGetDevices first, and the CurrentConnected and ChangeConnected flags are set there. + // note that certain titles such as Otogi need the ChangeConnected to be set to 1 always to enable the input. + int port; + if (DeviceType->CurrentConnected == 0) { + for (port = 0; port < 4; port++) { + //if the host controller is connected and the xbox DeviceType matches. set the CurrentConnected flag. + if (g_XboxControllerHostBridge[port].XboxDeviceInfo.DeviceType == DeviceType && g_XboxControllerHostBridge[port].dwHostType>0) { + DeviceType->CurrentConnected |= 1 << port; + } + } + DeviceType->ChangeConnected = DeviceType->CurrentConnected; } - + // JSRF Hack: Don't set the ChangeConnected flag. Without this, JSRF hard crashes if (TitleIsJSRF()) { DeviceType->ChangeConnected = 0; @@ -488,15 +488,15 @@ BOOL WINAPI XTL::EMUPATCH(XGetDeviceChanges) DeviceType->PreviousConnected = DeviceType->CurrentConnected; ret = (*pdwInsertions | *pdwRemovals) ? TRUE : FALSE; - xboxkrnl::KfLowerIrql(oldIrql); - } - - // Lego SW Hack: Require XGetDeviceChanges to return changes all the time, but no removal, only insertions. - // Without this, Lego SW will not response to controller's input. - if (TitleIsLegoSW()) { - *pdwRemovals = 0; - *pdwInsertions = DeviceType->CurrentConnected; - ret = TRUE; + xboxkrnl::KfLowerIrql(oldIrql); + } + + // Lego SW Hack: Require XGetDeviceChanges to return changes all the time, but no removal, only insertions. + // Without this, Lego SW will not response to controller's input. + if (TitleIsLegoSW()) { + *pdwRemovals = 0; + *pdwInsertions = DeviceType->CurrentConnected; + ret = TRUE; } RETURN(LOG_PREFIX, ret); @@ -520,10 +520,10 @@ HANDLE WINAPI XTL::EMUPATCH(XInputOpen) LOG_FUNC_ARG(dwPort) LOG_FUNC_ARG(dwSlot) LOG_FUNC_ARG(pPollingParameters) - LOG_FUNC_END; + LOG_FUNC_END; X_POLLING_PARAMETERS_HANDLE *pph = 0; - //OLD_XINPUT + //OLD_XINPUT //rever back to return handle for port 0~3, this is for multi controller support. /* if(dwPort >= 0 && (dwPort <= total_xinput_gamepad)) { @@ -573,42 +573,42 @@ HANDLE WINAPI XTL::EMUPATCH(XInputOpen) */ g_bXInputOpenCalled = true; - //RETURN(LOG_PREFIX, (HANDLE)pph); - //code above are not used at all, in future we might remove them. - if (dwPort >= 0 && dwPort < 4) { + //RETURN(LOG_PREFIX, (HANDLE)pph); + //code above are not used at all, in future we might remove them. + if (dwPort >= 0 && dwPort < 4) { //check if the bridged xbox controller at this port matches the DeviceType, if matches, setup the device handle and return it. if (g_XboxControllerHostBridge[dwPort].XboxDeviceInfo.DeviceType == DeviceType && g_XboxControllerHostBridge[dwPort].dwHostType!=0) { - //create the dialog for virtual SteelBatallion controller feedback status. - if(g_XboxControllerHostBridge[dwPort].dwHostType==X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_VIRTUAL_SBC){ - //if DLL not loaded yet, load it. - if (g_bCxbxVSBCLoaded != true) { - - g_module = LoadLibrary(TEXT("CxbxVSBC.dll")); - if (g_module != 0) { - g_bCxbxVSBCLoaded = true; - } - } - if(g_module!=0&& fnCxbxVSBCOpen==0){ - fnCxbxVSBCSetState = (PFARPROC2)GetProcAddress(g_module, "VSBCSetState"); - fnCxbxVSBCGetState = (PFARPROC2)GetProcAddress(g_module, "VSBCGetState"); - fnCxbxVSBCOpen = (PFARPROC1)GetProcAddress(g_module, "VSBCOpen"); - } - - if (fnCxbxVSBCOpen == 0) { - printf("EmuXapi: EmuXInputOpen: GetPRocAddress VSBCOpen failed!\n"); - } - else { - (*fnCxbxVSBCOpen)(X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_VIRTUAL_SBC); - } - //DWORD dwVXBCOpenResult = CxbxVSBC::MyCxbxVSBC::VSBCOpen(X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_VIRTUAL_SBC); - - } - g_XboxControllerHostBridge[dwPort].hXboxDevice = &g_XboxControllerHostBridge[dwPort]; + //create the dialog for virtual SteelBatallion controller feedback status. + if(g_XboxControllerHostBridge[dwPort].dwHostType==X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_VIRTUAL_SBC){ + //if DLL not loaded yet, load it. + if (g_bCxbxVSBCLoaded != true) { + + g_module = LoadLibrary(TEXT("CxbxVSBC.dll")); + if (g_module != 0) { + g_bCxbxVSBCLoaded = true; + } + } + if(g_module!=0&& fnCxbxVSBCOpen==0){ + fnCxbxVSBCSetState = (PFARPROC2)GetProcAddress(g_module, "VSBCSetState"); + fnCxbxVSBCGetState = (PFARPROC2)GetProcAddress(g_module, "VSBCGetState"); + fnCxbxVSBCOpen = (PFARPROC1)GetProcAddress(g_module, "VSBCOpen"); + } + + if (fnCxbxVSBCOpen == 0) { + printf("EmuXapi: EmuXInputOpen: GetPRocAddress VSBCOpen failed!\n"); + } + else { + (*fnCxbxVSBCOpen)(X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_VIRTUAL_SBC); + } + //DWORD dwVXBCOpenResult = CxbxVSBC::MyCxbxVSBC::VSBCOpen(X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_VIRTUAL_SBC); + + } + g_XboxControllerHostBridge[dwPort].hXboxDevice = &g_XboxControllerHostBridge[dwPort]; return g_XboxControllerHostBridge[dwPort].hXboxDevice; } - - } - + + } + return 0; } @@ -643,7 +643,7 @@ VOID WINAPI XTL::EMUPATCH(XInputClose) g_pXInputSetStateStatus[v].dwLatency = 0; } } - //OLD_XINPUT + //OLD_XINPUT /* if(pph->pPollingParameters != NULL) { @@ -652,15 +652,15 @@ VOID WINAPI XTL::EMUPATCH(XInputClose) delete pph; */ - } - - //above code is not used at all, in future we might remove them. - //reset hXboxDevice handle if it matches the hDevice - int port; - for(port=0;port<4;port++){ - if (g_XboxControllerHostBridge[dwPort].hXboxDevice == hDevice) { - g_XboxControllerHostBridge[dwPort].hXboxDevice=0; - break; + } + + //above code is not used at all, in future we might remove them. + //reset hXboxDevice handle if it matches the hDevice + int port; + for(port=0;port<4;port++){ + if (g_XboxControllerHostBridge[dwPort].hXboxDevice == hDevice) { + g_XboxControllerHostBridge[dwPort].hXboxDevice=0; + break; } } } @@ -675,7 +675,7 @@ DWORD WINAPI XTL::EMUPATCH(XInputPoll) { FUNC_EXPORTS - LOG_FUNC_ONE_ARG(LOG_PREFIX, hDevice); + LOG_FUNC_ONE_ARG(LOG_PREFIX, hDevice); //OLD_XINPUT /* X_POLLING_PARAMETERS_HANDLE *pph = (X_POLLING_PARAMETERS_HANDLE*)hDevice; @@ -714,27 +714,27 @@ DWORD WINAPI XTL::EMUPATCH(XInputPoll) } } } -*/ - int port; - for (port = 0; port<4; port++) { - if (g_XboxControllerHostBridge[port].hXboxDevice == hDevice) { - if (g_XboxControllerHostBridge[port].pXboxFeedbackHeader != 0) { - if (g_XboxControllerHostBridge[port].pXboxFeedbackHeader->dwStatus != ERROR_SUCCESS) { +*/ + int port; + for (port = 0; port<4; port++) { + if (g_XboxControllerHostBridge[port].hXboxDevice == hDevice) { + if (g_XboxControllerHostBridge[port].pXboxFeedbackHeader != 0) { + if (g_XboxControllerHostBridge[port].pXboxFeedbackHeader->dwStatus != ERROR_SUCCESS) { if (g_XboxControllerHostBridge[port].pXboxFeedbackHeader->hEvent != 0) { SetEvent(g_XboxControllerHostBridge[port].pXboxFeedbackHeader->hEvent); - } - g_XboxControllerHostBridge[port].pXboxFeedbackHeader->dwStatus = ERROR_SUCCESS; - break; - } - } - else { - break; - } + } + g_XboxControllerHostBridge[port].pXboxFeedbackHeader->dwStatus = ERROR_SUCCESS; + break; + } + } + else { + break; + } } - } - - + } + + RETURN(LOG_PREFIX, ERROR_SUCCESS); } @@ -771,253 +771,253 @@ DWORD WINAPI XTL::EMUPATCH(XInputGetCapabilities) ret = ERROR_SUCCESS; } - } + } */ - //above code is not used any more, could be removed. - //find XboxControllerHostBridge per hDevice, and fill the Capabilities Structure per Device Info - int port; - for (port = 0; port < 4; port++) { - if (g_XboxControllerHostBridge[port].hXboxDevice == hDevice) { - pCapabilities->SubType = g_XboxControllerHostBridge[port].XboxDeviceInfo.ucSubType; - //ready to set the In and Out structure in pCapabilities, shall set all bit to 1 for enabling the capabilities. - UCHAR * pCapa = (UCHAR *)(&pCapabilities->In); - - memset( pCapa, - 0xFF, - g_XboxControllerHostBridge[port].XboxDeviceInfo.ucInputStateSize + g_XboxControllerHostBridge[port].XboxDeviceInfo.ucFeedbackSize); - - ret = ERROR_SUCCESS; - break; - } - } + //above code is not used any more, could be removed. + //find XboxControllerHostBridge per hDevice, and fill the Capabilities Structure per Device Info + int port; + for (port = 0; port < 4; port++) { + if (g_XboxControllerHostBridge[port].hXboxDevice == hDevice) { + pCapabilities->SubType = g_XboxControllerHostBridge[port].XboxDeviceInfo.ucSubType; + //ready to set the In and Out structure in pCapabilities, shall set all bit to 1 for enabling the capabilities. + UCHAR * pCapa = (UCHAR *)(&pCapabilities->In); + + memset( pCapa, + 0xFF, + g_XboxControllerHostBridge[port].XboxDeviceInfo.ucInputStateSize + g_XboxControllerHostBridge[port].XboxDeviceInfo.ucFeedbackSize); + + ret = ERROR_SUCCESS; + break; + } + } RETURN(LOG_PREFIX, ret); } - -//variable names correlated to X_SBC_FEEDBACK, mapped to each nibble accordingly. -char * XboxSBCFeedbackNames[] = { - "EmergencyEject", - "CockpitHatch", - "Ignition", - "Start", - "OpenClose", - "MapZoomInOut", - "ModeSelect", - "SubMonitorModeSelect", - "MainMonitorZoomIn", - "MainMonitorZoomOut", - "ForecastShootingSystem", - "Manipulator", - "LineColorChange", - "Washing", - "Extinguisher", - "Chaff", - "TankDetach", - "Override", - "NightScope", - "F1", - "F2", - "F3", - "MainWeaponControl", - "SubWeaponControl", - "MagazineChange", - "Comm1", - "Comm2", - "Comm3", - "Comm4", - "Comm5", - "Unknown", - "GearR", - "GearN", - "Gear1", - "Gear2", - "Gear3", - "Gear4", - "Gear5" -}; - -//keep last SBC_GAMEPAD status, for DIP switch and GearLever -XTL::X_SBC_GAMEPAD XboxSBCGamepad = {}; - -//virtual SteelBatalion controller GetState, using port 0 from XInput and DirectInput to emulate virtual controller. -void EmuSBCGetState(XTL::PX_SBC_GAMEPAD pSBCGamepad, XTL::PX_XINPUT_GAMEPAD pXIGamepad, XTL::PX_XINPUT_GAMEPAD pDIGamepad) -{ - // Now convert those values to SteelBatalion Gamepad - - //restore certain variables such as GerLever and Toggle Switches. - - //restore the kept ucGearLever - pSBCGamepad->ucGearLever = XboxSBCGamepad.ucGearLever; - //we use continues range 7~13, 8 for gear N. - if (pSBCGamepad->ucGearLever < 7 || pSBCGamepad->ucGearLever>13) { - pSBCGamepad->ucGearLever = 8; - } - - //restore Toggle Switches. - pSBCGamepad->wButtons[0] |= (XboxSBCGamepad.wButtons[0] & (X_SBC_GAMEPAD_W0_COCKPITHATCH | X_SBC_GAMEPAD_W0_IGNITION)); - - pSBCGamepad->wButtons[2] |= (XboxSBCGamepad.wButtons[2]&( X_SBC_GAMEPAD_W2_TOGGLEFILTERCONTROL - | X_SBC_GAMEPAD_W2_TOGGLEOXYGENSUPPLY - | X_SBC_GAMEPAD_W2_TOGGLEFUELFLOWRATE - | X_SBC_GAMEPAD_W2_TOGGLEBUFFREMATERIAL - | X_SBC_GAMEPAD_W2_TOGGLEVTLOCATION)); - - - // Analog Sticks - pSBCGamepad->sAimingX = pXIGamepad->sThumbRX;; - pSBCGamepad->sAimingY = pXIGamepad->sThumbRY;; - pSBCGamepad->sRotationLever = 0;//(pXIGamepad->wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) ? 255 : 0; - pSBCGamepad->sSightChangeX = pXIGamepad->sThumbLX;; - pSBCGamepad->sSightChangeY = pXIGamepad->sThumbLY;; - pSBCGamepad->wLeftPedal = ((SHORT)(pXIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_LEFT_TRIGGER]))<<8; - pSBCGamepad->wMiddlePedal=0;// = (pXIGamepad->wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) ? 255 : 0; - pSBCGamepad->wRightPedal = (SHORT)(pXIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_RIGHT_TRIGGER])<<8; - pSBCGamepad->ucTunerDial=0;//low nibble - - - // Digital Buttons - if (pXIGamepad->bAnalogButtons [X_XINPUT_GAMEPAD_A]>0) { - pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_RIGHTJOYMAINWEAPON; - } - else { - pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_RIGHTJOYMAINWEAPON; - } - if (pXIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_B]>0) { - pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_RIGHTJOYFIRE; - } - else { - pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_RIGHTJOYFIRE; - } - if (pXIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_X]>0) { - pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_RIGHTJOYLOCKON; - } - else { - pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_RIGHTJOYLOCKON; - } - if (pXIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_Y]>0) { - pSBCGamepad->wButtons[1] |= X_SBC_GAMEPAD_W1_WEAPONCONMAGAZINE; - } - else { - pSBCGamepad->wButtons[1] &= ~X_SBC_GAMEPAD_W1_WEAPONCONMAGAZINE; - } - - //GearLever 1~5 for gear 1~5, 7~13 for gear R,N,1~5, 15 for gear R. we use the continues range from 7~13 - if (pXIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_WHITE]>0) {//Left Shouder, Gear Down - if (pSBCGamepad->ucGearLever >7) { - pSBCGamepad->ucGearLever-- ; - } - } - - if (pXIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_BLACK]>0) {//Right Shouder, Gear Up - if (pSBCGamepad->ucGearLever < 13) { - pSBCGamepad->ucGearLever ++; - } - } - //OLD_XINPUT - /* //not used, don't duplicate the handling for same setting of pXIGamepad's members, later one will over write privous one. - if (pXIGamepad->wButtons & X_XINPUT_GAMEPAD_START) { - pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_START; - } - else { - pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_START; - } - */ - if (pXIGamepad->wButtons & X_XINPUT_GAMEPAD_LEFT_THUMB) {//Center Sight Change - pSBCGamepad->wButtons[2] |= X_SBC_GAMEPAD_W2_LEFTJOYSIGHTCHANGE; - } - else { - pSBCGamepad->wButtons[2] &= ~X_SBC_GAMEPAD_W2_LEFTJOYSIGHTCHANGE; - } - //OLD_XINPUT - /* //not used - if (pXIGamepad->wButtons & X_XINPUT_GAMEPAD_RIGHT_THUMB) { - pSBCGamepad->wButtons |= X_XINPUT_GAMEPAD_RIGHT_THUMB; - } - else { - pSBCGamepad->wButtons &= ~X_XINPUT_GAMEPAD_RIGHT_THUMB; - } - */ - - - //additional input from 2nd input, default using directinput - if (pDIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_A]>0) { - pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_START; - } - else { - pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_START; - } - // Iginition is Toggle Switch - if (pDIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_B]>0) { - if (pSBCGamepad->wButtons[0] & X_SBC_GAMEPAD_W0_IGNITION) { - pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_IGNITION; - } - else { - pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_IGNITION; - } - } - - if (pDIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_X]>0) { - pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_EJECT; - } - else { - pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_EJECT; - } - // CockpitHatch is Toggle Switch - if (pDIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_Y]>0) { - if (pSBCGamepad->wButtons[0] & X_SBC_GAMEPAD_W0_COCKPITHATCH) { - pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_COCKPITHATCH; - } - else { - pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_COCKPITHATCH; - } - } - - if (pDIGamepad->wButtons & X_XINPUT_GAMEPAD_BACK) {//Toggle Switch ToggleFilterControl - if (pSBCGamepad->wButtons[2] & X_SBC_GAMEPAD_W2_TOGGLEFILTERCONTROL) { - pSBCGamepad->wButtons[2] &= ~X_SBC_GAMEPAD_W2_TOGGLEFILTERCONTROL; - } - else { - pSBCGamepad->wButtons[2] |= X_SBC_GAMEPAD_W2_TOGGLEFILTERCONTROL; - } - } - - if (pDIGamepad->wButtons & X_XINPUT_GAMEPAD_DPAD_UP) {//Toggle Switch ToggleOxygenSupply - if (pSBCGamepad->wButtons[2] & X_SBC_GAMEPAD_W2_TOGGLEOXYGENSUPPLY) { - pSBCGamepad->wButtons[2] &= ~X_SBC_GAMEPAD_W2_TOGGLEOXYGENSUPPLY; - } - else { - pSBCGamepad->wButtons[2] |= X_SBC_GAMEPAD_W2_TOGGLEOXYGENSUPPLY; - } - } - - if (pDIGamepad->wButtons & X_XINPUT_GAMEPAD_DPAD_DOWN) {//Toggle Switch ToggleBuffreMaterial - if (pSBCGamepad->wButtons[2] & X_SBC_GAMEPAD_W2_TOGGLEBUFFREMATERIAL) { - pSBCGamepad->wButtons[2] &= ~X_SBC_GAMEPAD_W2_TOGGLEBUFFREMATERIAL; - } - else { - pSBCGamepad->wButtons[2] |= X_SBC_GAMEPAD_W2_TOGGLEBUFFREMATERIAL; - } - } - - if (pDIGamepad->wButtons & X_XINPUT_GAMEPAD_DPAD_LEFT) {//Toggle Switch ToggleVTLocation - if (pSBCGamepad->wButtons[2] & X_SBC_GAMEPAD_W2_TOGGLEVTLOCATION) { - pSBCGamepad->wButtons[2] &= ~X_SBC_GAMEPAD_W2_TOGGLEVTLOCATION; - } - else { - pSBCGamepad->wButtons[2] |= X_SBC_GAMEPAD_W2_TOGGLEVTLOCATION; - } - } - - if (pDIGamepad->wButtons & X_XINPUT_GAMEPAD_DPAD_RIGHT) {//Toggle Switch ToggleFuelFlowRate - if (pSBCGamepad->wButtons[2] & X_SBC_GAMEPAD_W2_TOGGLEFUELFLOWRATE) { - pSBCGamepad->wButtons[2] &= ~X_SBC_GAMEPAD_W2_TOGGLEFUELFLOWRATE; - } - else { - pSBCGamepad->wButtons[2] |= X_SBC_GAMEPAD_W2_TOGGLEFUELFLOWRATE; - } - } - //reserve the SBCGamepad to keep the status of GearLever and Toggole Switches. - XboxSBCGamepad = *pSBCGamepad; + +//variable names correlated to X_SBC_FEEDBACK, mapped to each nibble accordingly. +char * XboxSBCFeedbackNames[] = { + "EmergencyEject", + "CockpitHatch", + "Ignition", + "Start", + "OpenClose", + "MapZoomInOut", + "ModeSelect", + "SubMonitorModeSelect", + "MainMonitorZoomIn", + "MainMonitorZoomOut", + "ForecastShootingSystem", + "Manipulator", + "LineColorChange", + "Washing", + "Extinguisher", + "Chaff", + "TankDetach", + "Override", + "NightScope", + "F1", + "F2", + "F3", + "MainWeaponControl", + "SubWeaponControl", + "MagazineChange", + "Comm1", + "Comm2", + "Comm3", + "Comm4", + "Comm5", + "Unknown", + "GearR", + "GearN", + "Gear1", + "Gear2", + "Gear3", + "Gear4", + "Gear5" +}; + +//keep last SBC_GAMEPAD status, for DIP switch and GearLever +XTL::X_SBC_GAMEPAD XboxSBCGamepad = {}; + +//virtual SteelBatalion controller GetState, using port 0 from XInput and DirectInput to emulate virtual controller. +void EmuSBCGetState(XTL::PX_SBC_GAMEPAD pSBCGamepad, XTL::PX_XINPUT_GAMEPAD pXIGamepad, XTL::PX_XINPUT_GAMEPAD pDIGamepad) +{ + // Now convert those values to SteelBatalion Gamepad + + //restore certain variables such as GerLever and Toggle Switches. + + //restore the kept ucGearLever + pSBCGamepad->ucGearLever = XboxSBCGamepad.ucGearLever; + //we use continues range 7~13, 8 for gear N. + if (pSBCGamepad->ucGearLever < 7 || pSBCGamepad->ucGearLever>13) { + pSBCGamepad->ucGearLever = 8; + } + + //restore Toggle Switches. + pSBCGamepad->wButtons[0] |= (XboxSBCGamepad.wButtons[0] & (X_SBC_GAMEPAD_W0_COCKPITHATCH | X_SBC_GAMEPAD_W0_IGNITION)); + + pSBCGamepad->wButtons[2] |= (XboxSBCGamepad.wButtons[2]&( X_SBC_GAMEPAD_W2_TOGGLEFILTERCONTROL + | X_SBC_GAMEPAD_W2_TOGGLEOXYGENSUPPLY + | X_SBC_GAMEPAD_W2_TOGGLEFUELFLOWRATE + | X_SBC_GAMEPAD_W2_TOGGLEBUFFREMATERIAL + | X_SBC_GAMEPAD_W2_TOGGLEVTLOCATION)); + + + // Analog Sticks + pSBCGamepad->sAimingX = pXIGamepad->sThumbRX;; + pSBCGamepad->sAimingY = pXIGamepad->sThumbRY;; + pSBCGamepad->sRotationLever = 0;//(pXIGamepad->wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) ? 255 : 0; + pSBCGamepad->sSightChangeX = pXIGamepad->sThumbLX;; + pSBCGamepad->sSightChangeY = pXIGamepad->sThumbLY;; + pSBCGamepad->wLeftPedal = ((SHORT)(pXIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_LEFT_TRIGGER]))<<8; + pSBCGamepad->wMiddlePedal=0;// = (pXIGamepad->wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) ? 255 : 0; + pSBCGamepad->wRightPedal = (SHORT)(pXIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_RIGHT_TRIGGER])<<8; + pSBCGamepad->ucTunerDial=0;//low nibble + + + // Digital Buttons + if (pXIGamepad->bAnalogButtons [X_XINPUT_GAMEPAD_A]>0) { + pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_RIGHTJOYMAINWEAPON; + } + else { + pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_RIGHTJOYMAINWEAPON; + } + if (pXIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_B]>0) { + pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_RIGHTJOYFIRE; + } + else { + pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_RIGHTJOYFIRE; + } + if (pXIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_X]>0) { + pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_RIGHTJOYLOCKON; + } + else { + pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_RIGHTJOYLOCKON; + } + if (pXIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_Y]>0) { + pSBCGamepad->wButtons[1] |= X_SBC_GAMEPAD_W1_WEAPONCONMAGAZINE; + } + else { + pSBCGamepad->wButtons[1] &= ~X_SBC_GAMEPAD_W1_WEAPONCONMAGAZINE; + } + + //GearLever 1~5 for gear 1~5, 7~13 for gear R,N,1~5, 15 for gear R. we use the continues range from 7~13 + if (pXIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_WHITE]>0) {//Left Shouder, Gear Down + if (pSBCGamepad->ucGearLever >7) { + pSBCGamepad->ucGearLever-- ; + } + } + + if (pXIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_BLACK]>0) {//Right Shouder, Gear Up + if (pSBCGamepad->ucGearLever < 13) { + pSBCGamepad->ucGearLever ++; + } + } + //OLD_XINPUT + /* //not used, don't duplicate the handling for same setting of pXIGamepad's members, later one will over write privous one. + if (pXIGamepad->wButtons & X_XINPUT_GAMEPAD_START) { + pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_START; + } + else { + pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_START; + } + */ + if (pXIGamepad->wButtons & X_XINPUT_GAMEPAD_LEFT_THUMB) {//Center Sight Change + pSBCGamepad->wButtons[2] |= X_SBC_GAMEPAD_W2_LEFTJOYSIGHTCHANGE; + } + else { + pSBCGamepad->wButtons[2] &= ~X_SBC_GAMEPAD_W2_LEFTJOYSIGHTCHANGE; + } + //OLD_XINPUT + /* //not used + if (pXIGamepad->wButtons & X_XINPUT_GAMEPAD_RIGHT_THUMB) { + pSBCGamepad->wButtons |= X_XINPUT_GAMEPAD_RIGHT_THUMB; + } + else { + pSBCGamepad->wButtons &= ~X_XINPUT_GAMEPAD_RIGHT_THUMB; + } + */ + + + //additional input from 2nd input, default using directinput + if (pDIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_A]>0) { + pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_START; + } + else { + pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_START; + } + // Iginition is Toggle Switch + if (pDIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_B]>0) { + if (pSBCGamepad->wButtons[0] & X_SBC_GAMEPAD_W0_IGNITION) { + pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_IGNITION; + } + else { + pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_IGNITION; + } + } + + if (pDIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_X]>0) { + pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_EJECT; + } + else { + pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_EJECT; + } + // CockpitHatch is Toggle Switch + if (pDIGamepad->bAnalogButtons[X_XINPUT_GAMEPAD_Y]>0) { + if (pSBCGamepad->wButtons[0] & X_SBC_GAMEPAD_W0_COCKPITHATCH) { + pSBCGamepad->wButtons[0] &= ~X_SBC_GAMEPAD_W0_COCKPITHATCH; + } + else { + pSBCGamepad->wButtons[0] |= X_SBC_GAMEPAD_W0_COCKPITHATCH; + } + } + + if (pDIGamepad->wButtons & X_XINPUT_GAMEPAD_BACK) {//Toggle Switch ToggleFilterControl + if (pSBCGamepad->wButtons[2] & X_SBC_GAMEPAD_W2_TOGGLEFILTERCONTROL) { + pSBCGamepad->wButtons[2] &= ~X_SBC_GAMEPAD_W2_TOGGLEFILTERCONTROL; + } + else { + pSBCGamepad->wButtons[2] |= X_SBC_GAMEPAD_W2_TOGGLEFILTERCONTROL; + } + } + + if (pDIGamepad->wButtons & X_XINPUT_GAMEPAD_DPAD_UP) {//Toggle Switch ToggleOxygenSupply + if (pSBCGamepad->wButtons[2] & X_SBC_GAMEPAD_W2_TOGGLEOXYGENSUPPLY) { + pSBCGamepad->wButtons[2] &= ~X_SBC_GAMEPAD_W2_TOGGLEOXYGENSUPPLY; + } + else { + pSBCGamepad->wButtons[2] |= X_SBC_GAMEPAD_W2_TOGGLEOXYGENSUPPLY; + } + } + + if (pDIGamepad->wButtons & X_XINPUT_GAMEPAD_DPAD_DOWN) {//Toggle Switch ToggleBuffreMaterial + if (pSBCGamepad->wButtons[2] & X_SBC_GAMEPAD_W2_TOGGLEBUFFREMATERIAL) { + pSBCGamepad->wButtons[2] &= ~X_SBC_GAMEPAD_W2_TOGGLEBUFFREMATERIAL; + } + else { + pSBCGamepad->wButtons[2] |= X_SBC_GAMEPAD_W2_TOGGLEBUFFREMATERIAL; + } + } + + if (pDIGamepad->wButtons & X_XINPUT_GAMEPAD_DPAD_LEFT) {//Toggle Switch ToggleVTLocation + if (pSBCGamepad->wButtons[2] & X_SBC_GAMEPAD_W2_TOGGLEVTLOCATION) { + pSBCGamepad->wButtons[2] &= ~X_SBC_GAMEPAD_W2_TOGGLEVTLOCATION; + } + else { + pSBCGamepad->wButtons[2] |= X_SBC_GAMEPAD_W2_TOGGLEVTLOCATION; + } + } + + if (pDIGamepad->wButtons & X_XINPUT_GAMEPAD_DPAD_RIGHT) {//Toggle Switch ToggleFuelFlowRate + if (pSBCGamepad->wButtons[2] & X_SBC_GAMEPAD_W2_TOGGLEFUELFLOWRATE) { + pSBCGamepad->wButtons[2] &= ~X_SBC_GAMEPAD_W2_TOGGLEFUELFLOWRATE; + } + else { + pSBCGamepad->wButtons[2] |= X_SBC_GAMEPAD_W2_TOGGLEFUELFLOWRATE; + } + } + //reserve the SBCGamepad to keep the status of GearLever and Toggole Switches. + XboxSBCGamepad = *pSBCGamepad; } // ****************************************************************** // * patch: XInputGetState @@ -1037,7 +1037,7 @@ DWORD WINAPI XTL::EMUPATCH(XInputGetState) DWORD ret = ERROR_INVALID_HANDLE; //OLD_XINPUT - /* + /* X_POLLING_PARAMETERS_HANDLE *pph = (X_POLLING_PARAMETERS_HANDLE*)hDevice; if(pph != NULL) @@ -1050,7 +1050,7 @@ DWORD WINAPI XTL::EMUPATCH(XInputGetState) // TODO: uh.. // - EmuWarning("EmuXInputGetState : fAutoPoll == FALSE"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuXInputGetState : fAutoPoll == FALSE"); } } @@ -1058,7 +1058,7 @@ DWORD WINAPI XTL::EMUPATCH(XInputGetState) if((dwPort >= 0) && (dwPort <= total_xinput_gamepad)) { - DbgPrintf("XAPI: EmuXInputGetState(): dwPort = %d\n", dwPort ); + DbgPrintf(LOG_PREFIX, "EmuXInputGetState(): dwPort = %d\n", dwPort ); //for xinput, we query the state corresponds to port. if (g_XInputEnabled) { @@ -1071,45 +1071,45 @@ DWORD WINAPI XTL::EMUPATCH(XInputGetState) } } else - EmuWarning("EmuXInputGetState(): pph == NULL!"); - */ - //above code is not used at all, in future we might remove them. - //get input state if hXboxDevice matches hDevice - int port; - for (port = 0; port<4; port++) { - if (g_XboxControllerHostBridge[port].hXboxDevice == hDevice) { - + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuXInputGetState(): pph == NULL!"); + */ + //above code is not used at all, in future we might remove them. + //get input state if hXboxDevice matches hDevice + int port; + for (port = 0; port<4; port++) { + if (g_XboxControllerHostBridge[port].hXboxDevice == hDevice) { + //for xinput, we query the state corresponds to port. - switch (g_XboxControllerHostBridge[port].dwHostType) { + switch (g_XboxControllerHostBridge[port].dwHostType) { case X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_XINPUT://using XInput - EmuXInputPCPoll(g_XboxControllerHostBridge[port].dwHostPort, pState); - ret = ERROR_SUCCESS; - break; - case X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_DINPUT://using directinput - EmuDInputPoll(pState); - ret = ERROR_SUCCESS; - break; - case X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_VIRTUAL_SBC://using virtual SteelBatalion Controller - //printf("SBC get state!\n"); - XTL::X_XINPUT_STATE InputState0, InputState1; - InputState0 = {}; - InputState1 = {}; - EmuXInputPCPoll(0, &InputState0); - EmuDInputPoll(&InputState1); - pState->dwPacketNumber = InputState0.dwPacketNumber; - EmuSBCGetState(XTL::PX_SBC_GAMEPAD(&pState->Gamepad), &InputState0.Gamepad, &InputState1.Gamepad); - break; - default: + EmuXInputPCPoll(g_XboxControllerHostBridge[port].dwHostPort, pState); + ret = ERROR_SUCCESS; break; - } - - break; + case X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_DINPUT://using directinput + EmuDInputPoll(pState); + ret = ERROR_SUCCESS; + break; + case X_XONTROLLER_HOST_BRIDGE_HOSTTYPE_VIRTUAL_SBC://using virtual SteelBatalion Controller + //printf("SBC get state!\n"); + XTL::X_XINPUT_STATE InputState0, InputState1; + InputState0 = {}; + InputState1 = {}; + EmuXInputPCPoll(0, &InputState0); + EmuDInputPoll(&InputState1); + pState->dwPacketNumber = InputState0.dwPacketNumber; + EmuSBCGetState(XTL::PX_SBC_GAMEPAD(&pState->Gamepad), &InputState0.Gamepad, &InputState1.Gamepad); + break; + default: + break; + } + + break; } } RETURN(LOG_PREFIX, ret); -} - +} + // ****************************************************************** // * patch: XInputSetState // ****************************************************************** @@ -1124,9 +1124,9 @@ DWORD WINAPI XTL::EMUPATCH(XInputSetState) LOG_FUNC_BEGIN(LOG_PREFIX) LOG_FUNC_ARG(hDevice) LOG_FUNC_ARG(pFeedback) - LOG_FUNC_END; + LOG_FUNC_END; - DWORD ret = ERROR_IO_PENDING; + DWORD ret = ERROR_IO_PENDING; //OLD_XINPUT /* X_POLLING_PARAMETERS_HANDLE *pph = (X_POLLING_PARAMETERS_HANDLE*)hDevice; @@ -1182,7 +1182,7 @@ DWORD WINAPI XTL::EMUPATCH(XInputSetState) if(v == XINPUT_SETSTATE_SLOTS) { - CxbxKrnlCleanup("Ran out of XInputSetStateStatus slots!"); + CxbxKrnlCleanup(LOG_PREFIX, "Ran out of XInputSetStateStatus slots!"); } } @@ -1191,52 +1191,52 @@ DWORD WINAPI XTL::EMUPATCH(XInputSetState) XTL::EmuXInputSetState(pph->dwPort, pFeedback); } } - */ - - //above code is not used at all, in future we might remove them. - //reset hXboxDevice handle if it matches the hDevice - int port; - for (port = 0; port<4; port++) { - if (g_XboxControllerHostBridge[port].hXboxDevice == hDevice) { - //if (g_XboxControllerHostBridge[port].pXboxFeedbackHeader == 0) { - g_XboxControllerHostBridge[port].pXboxFeedbackHeader = &pFeedback->Header; - g_XboxControllerHostBridge[port].dwLatency = 0; - pFeedback->Header.dwStatus = ERROR_IO_PENDING; - ret = ERROR_IO_PENDING; - //set XInput State if host type is Xinput. - switch (g_XboxControllerHostBridge[port].dwHostType) { - case 1://using XInput - XTL::EmuXInputSetState(port, pFeedback); - break; - case 2://using directinput - break; - case 0x80://using virtual SteelBatalion Controller - //printf("SBC setstate!\n"); - //EmuXSBCSetState((UCHAR *)&pFeedback->Rumble); - //UpdateVirtualSBCFeedbackDlg((UCHAR *)&pFeedback->Rumble); - //DWORD dwVXBCSetStateResult; - if (g_module != 0 && fnCxbxVSBCSetState == 0) { - fnCxbxVSBCSetState = (PFARPROC2)GetProcAddress(g_module, "VSBCSetState"); - //fnCxbxVSBCGetState = (PFARPROC2)GetProcAddress(g_module, "VSBCGetState"); - //fnCxbxVSBCOpen = (PFARPROC1)GetProcAddress(g_module, "VSBCOpen"); - } - if (fnCxbxVSBCSetState == 0) { - printf("EmuXapi: EmuXInputSetState: GetPRocAddress VSBCSetState failed!\n"); - } - else { - (*fnCxbxVSBCSetState)((UCHAR *)&pFeedback->Rumble); - } - - - //dwVXBCSetStateResult = CxbxVSBC::MyCxbxVSBC::VSBCSetState((UCHAR *)&pFeedback->Rumble); - break; - default: + */ + + //above code is not used at all, in future we might remove them. + //reset hXboxDevice handle if it matches the hDevice + int port; + for (port = 0; port<4; port++) { + if (g_XboxControllerHostBridge[port].hXboxDevice == hDevice) { + //if (g_XboxControllerHostBridge[port].pXboxFeedbackHeader == 0) { + g_XboxControllerHostBridge[port].pXboxFeedbackHeader = &pFeedback->Header; + g_XboxControllerHostBridge[port].dwLatency = 0; + pFeedback->Header.dwStatus = ERROR_IO_PENDING; + ret = ERROR_IO_PENDING; + //set XInput State if host type is Xinput. + switch (g_XboxControllerHostBridge[port].dwHostType) { + case 1://using XInput + XTL::EmuXInputSetState(port, pFeedback); break; - } - break; - //} + case 2://using directinput + break; + case 0x80://using virtual SteelBatalion Controller + //printf("SBC setstate!\n"); + //EmuXSBCSetState((UCHAR *)&pFeedback->Rumble); + //UpdateVirtualSBCFeedbackDlg((UCHAR *)&pFeedback->Rumble); + //DWORD dwVXBCSetStateResult; + if (g_module != 0 && fnCxbxVSBCSetState == 0) { + fnCxbxVSBCSetState = (PFARPROC2)GetProcAddress(g_module, "VSBCSetState"); + //fnCxbxVSBCGetState = (PFARPROC2)GetProcAddress(g_module, "VSBCGetState"); + //fnCxbxVSBCOpen = (PFARPROC1)GetProcAddress(g_module, "VSBCOpen"); + } + if (fnCxbxVSBCSetState == 0) { + printf("EmuXapi: EmuXInputSetState: GetPRocAddress VSBCSetState failed!\n"); + } + else { + (*fnCxbxVSBCSetState)((UCHAR *)&pFeedback->Rumble); + } + + + //dwVXBCSetStateResult = CxbxVSBC::MyCxbxVSBC::VSBCSetState((UCHAR *)&pFeedback->Rumble); + break; + default: + break; + } + break; + //} } - } + } RETURN(LOG_PREFIX, ret); } @@ -1261,7 +1261,7 @@ BOOL WINAPI XTL::EMUPATCH(SetThreadPriorityBoost) BOOL bRet = SetThreadPriorityBoost(hThread, DisablePriorityBoost); if(bRet == FALSE) - EmuWarning("SetThreadPriorityBoost Failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "SetThreadPriorityBoost Failed!"); RETURN(LOG_PREFIX, bRet); } @@ -1285,7 +1285,7 @@ BOOL WINAPI XTL::EMUPATCH(SetThreadPriority) BOOL bRet = SetThreadPriority(hThread, nPriority); if(bRet == FALSE) - EmuWarning("SetThreadPriority Failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "SetThreadPriority Failed!"); RETURN(LOG_PREFIX, bRet); } @@ -1306,7 +1306,7 @@ int WINAPI XTL::EMUPATCH(GetThreadPriority) int iRet = GetThreadPriority(hThread); if(iRet == THREAD_PRIORITY_ERROR_RETURN) - EmuWarning("GetThreadPriority Failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "GetThreadPriority Failed!"); RETURN(LOG_PREFIX, iRet); } @@ -1387,7 +1387,7 @@ VOID WINAPI XTL::EMUPATCH(XRegisterThreadNotifyRoutine) { // I honestly don't expect this to happen, but if it does... if(g_iThreadNotificationCount >= 16) - CxbxKrnlCleanup("Too many thread notification routines installed\n"); + CxbxKrnlCleanup(LOG_PREFIX, "Too many thread notification routines installed\n"); // Find an empty spot in the thread notification array for(int i = 0; i < 16; i++) @@ -1423,15 +1423,15 @@ typedef struct { } fiber_context_t; void WINAPI EmuFiberStartup(fiber_context_t* context) -{ - __try - { +{ + __try + { LPFIBER_START_ROUTINE pfStartRoutine = (LPFIBER_START_ROUTINE)context->lpStartRoutine; - pfStartRoutine(context->lpParameter); - } - __except (EmuException(GetExceptionInformation())) - { - EmuWarning("Problem with ExceptionFilter"); + pfStartRoutine(context->lpParameter); + } + __except (EmuException(GetExceptionInformation())) + { + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Problem with ExceptionFilter"); } } @@ -1507,18 +1507,18 @@ LPVOID WINAPI XTL::EMUPATCH(ConvertThreadToFiber) RETURN(LOG_PREFIX, pRet); } -// ****************************************************************** -// * patch: QueryPerformanceCounter -// ****************************************************************** -BOOL WINAPI XTL::EMUPATCH(QueryPerformanceCounter) -( - LARGE_INTEGER * lpPerformanceCount -) -{ - FUNC_EXPORTS; - - lpPerformanceCount->QuadPart = xboxkrnl::KeQueryPerformanceCounter(); - return TRUE; +// ****************************************************************** +// * patch: QueryPerformanceCounter +// ****************************************************************** +BOOL WINAPI XTL::EMUPATCH(QueryPerformanceCounter) +( + LARGE_INTEGER * lpPerformanceCount +) +{ + FUNC_EXPORTS; + + lpPerformanceCount->QuadPart = xboxkrnl::KeQueryPerformanceCounter(); + return TRUE; } // ****************************************************************** @@ -1546,11 +1546,11 @@ DWORD WINAPI XTL::EMUPATCH(QueueUserAPC) HANDLE hApcThread = NULL; if(!DuplicateHandle(g_CurrentProcessHandle, hThread, g_CurrentProcessHandle, &hApcThread, THREAD_SET_CONTEXT,FALSE,0)) - EmuWarning("DuplicateHandle failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "DuplicateHandle failed!"); dwRet = QueueUserAPC(pfnAPC, hApcThread, dwData); if(!dwRet) - EmuWarning("QueueUserAPC failed!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "QueueUserAPC failed!"); RETURN(LOG_PREFIX, dwRet); } @@ -1652,7 +1652,7 @@ DWORD WINAPI XTL::EMUPATCH(XLaunchNewImageA) // Other options include LDT_NONE, LDT_FROM_DEBUGGER_CMDLINE and LDT_FROM_UPDATE } else - CxbxKrnlCleanup("The xbe rebooted to Dashboard and xboxdash.xbe could not be found"); + CxbxKrnlCleanup(LOG_PREFIX, "The xbe rebooted to Dashboard and xboxdash.xbe could not be found"); } strncpy(&(xboxkrnl::LaunchDataPage->Header.szLaunchPath[0]), lpTitlePath, 520); @@ -1686,7 +1686,7 @@ DWORD WINAPI XTL::EMUPATCH(XGetLaunchInfo) // For this, we need a test-case that hits this function, and run that // with and without this patch enabled. Behavior should be identical. // When this is verified, this patch can be removed. - LOG_TEST_CASE("Unpatching test needed"); + LOG_TEST_CASE(LOG_PREFIX, "Unpatching test needed"); LOG_FUNC_BEGIN(LOG_PREFIX) LOG_FUNC_ARG(pdwLaunchDataType) diff --git a/src/CxbxKrnl/HLEIntercept.cpp b/src/CxbxKrnl/HLEIntercept.cpp index 86d75d9e8..bcc29852e 100644 --- a/src/CxbxKrnl/HLEIntercept.cpp +++ b/src/CxbxKrnl/HLEIntercept.cpp @@ -145,7 +145,8 @@ bool VerifySymbolAddressAgainstXRef(char *SymbolName, xbaddr Address, int XRef) } // For XREF_D3DTSS_TEXCOORDINDEX, Kabuki Warriors hits this case - CxbxPopupMessage("Verification of %s failed : XREF was 0x%.8X while lookup gave 0x%.8X", SymbolName, XRefAddr, Address); + CxbxPopupMessage(LOG_PREFIX, LOG_LEVEL::WARNING, CxbxMsgDlgIcon_Warn, + "Verification of %s failed : XREF was 0x%.8X while lookup gave 0x%.8X", SymbolName, XRefAddr, Address); // For XREF_D3DTSS_TEXCOORDINDEX, Kabuki Warriors hits this case return false; }*/ @@ -181,11 +182,11 @@ void CDECL EmuOutputMessage(xb_output_message mFlag, break; } case XB_OUTPUT_MESSAGE_WARN: { - EmuWarning("%s", message); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "%s", message); break; } case XB_OUTPUT_MESSAGE_ERROR: { - CxbxKrnlCleanup("%s", message); + CxbxKrnlCleanup(LOG_PREFIX, "%s", message); break; } case XB_OUTPUT_MESSAGE_DEBUG: @@ -227,7 +228,7 @@ void CDECL EmuRegisterSymbol(const char* library_str, switch (XRefDataBase[Oovpa->XRefSaveIndex]) { case XREF_ADDR_NOT_FOUND: { - EmuWarning("Found OOVPA after first finding nothing?"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Found OOVPA after first finding nothing?"); // fallthrough to XREF_ADDR_UNDETERMINED } case XREF_ADDR_UNDETERMINED: @@ -239,14 +240,14 @@ void CDECL EmuRegisterSymbol(const char* library_str, } case XREF_ADDR_DERIVE: { - EmuWarning("Cannot derive a save index!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Cannot derive a save index!"); break; } default: { if (XRefDataBase[OovpaTable->Oovpa->XRefSaveIndex] != pFunc) { - EmuWarning("Found OOVPA on other address than in XRefDataBase!"); - EmuWarning("%s: %4d - pFunc: %08X, stored: %08X", OovpaTable->szFuncName, Oovpa->XRefSaveIndex, pFunc, XRefDataBase[Oovpa->XRefSaveIndex]); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Found OOVPA on other address than in XRefDataBase!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "%s: %4d - pFunc: %08X, stored: %08X", OovpaTable->szFuncName, Oovpa->XRefSaveIndex, pFunc, XRefDataBase[Oovpa->XRefSaveIndex]); } break; } @@ -414,7 +415,7 @@ void EmuHLEIntercept(Xbe::Header *pXbeHeader) std::string cachePath = std::string(szFolder_CxbxReloadedData) + "\\HLECache\\"; int result = SHCreateDirectoryEx(nullptr, cachePath.c_str(), nullptr); if ((result != ERROR_SUCCESS) && (result != ERROR_ALREADY_EXISTS)) { - CxbxKrnlCleanup("Couldn't create Cxbx-Reloaded HLECache folder!"); + CxbxKrnlCleanup(LOG_PREFIX, "Couldn't create Cxbx-Reloaded HLECache folder!"); } // Hash the loaded XBE's header, use it as a filename @@ -507,17 +508,17 @@ void EmuHLEIntercept(Xbe::Header *pXbeHeader) // Fix up Render state and Texture States if (g_SymbolAddresses.find("D3DDeferredRenderState") == g_SymbolAddresses.end() || g_SymbolAddresses["D3DDeferredRenderState"] == 0) { - EmuWarning("EmuD3DDeferredRenderState was not found!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuD3DDeferredRenderState was not found!"); } if (g_SymbolAddresses.find("D3DDeferredTextureState") == g_SymbolAddresses.end() || g_SymbolAddresses["D3DDeferredTextureState"] == 0) { - EmuWarning("EmuD3DDeferredTextureState was not found!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "EmuD3DDeferredTextureState was not found!"); } if (g_SymbolAddresses.find("D3DDEVICE") == g_SymbolAddresses.end() || g_SymbolAddresses["D3DDEVICE"] == 0) { - EmuWarning("D3DDEVICE was not found!"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "D3DDEVICE was not found!"); } EmuD3D_Init_DeferredStates(); @@ -549,7 +550,7 @@ void EmuHLEIntercept(Xbe::Header *pXbeHeader) } #if 0 // NOTE: This is a note for what we should do for above. if (BuildVersion >= 5558 && BuildVersion <= 5659 && QFEVersion > 1) { - EmuWarning("D3D8 version 1.0.%d.%d Title Detected: This game uses an alias version 1.0.5788", BuildVersion, QFEVersion); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "D3D8 version 1.0.%d.%d Title Detected: This game uses an alias version 1.0.5788", BuildVersion, QFEVersion); BuildVersion = 5788; } #endif diff --git a/src/CxbxKrnl/PhysicalMemory.cpp b/src/CxbxKrnl/PhysicalMemory.cpp index 65e8cca87..e949ea89b 100644 --- a/src/CxbxKrnl/PhysicalMemory.cpp +++ b/src/CxbxKrnl/PhysicalMemory.cpp @@ -553,7 +553,7 @@ DWORD PhysicalMemory::PatchXboxPermissions(DWORD Perms) { // One of XBOX_PAGE_READONLY or XBOX_PAGE_READWRITE must be specified - DbgPrintf("PMEM: PatchXboxPermissions: Memory permissions bug detected\n"); + DbgPrintf(LOG_PREFIX, "%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("PMEM: PatchXboxPermissions: Memory permissions bug detected\n"); + DbgPrintf(LOG_PREFIX, "%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("PMEM: ConvertXboxToWinProtection: Memory permissions bug detected\n"); + DbgPrintf(LOG_PREFIX, "%s: Memory permissions bug detected\n", __func__); return PAGE_EXECUTE_READWRITE; } } @@ -738,7 +738,7 @@ bool PhysicalMemory::IsMappable(PFN_COUNT PagesRequested, bool bRetailRegion, bo bool ret = false; if (bRetailRegion && m_PhysicalPagesAvailable >= PagesRequested) { ret = true; } if (bDebugRegion && m_DebuggerPagesAvailable >= PagesRequested) { ret = true; } - if (!ret) { EmuWarning(LOG_PREFIX " Out of physical memory!"); } + if (!ret) { EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Out of physical memory!"); } return ret; } diff --git a/src/CxbxKrnl/PoolManager.cpp b/src/CxbxKrnl/PoolManager.cpp index 6f2fe7753..cee6daa5d 100644 --- a/src/CxbxKrnl/PoolManager.cpp +++ b/src/CxbxKrnl/PoolManager.cpp @@ -111,7 +111,7 @@ VAddr PoolManager::AllocatePool(size_t Size, uint32_t Tag) Unlock(); } else { - EmuWarning(LOG_PREFIX " AllocatePool returns nullptr"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "AllocatePool returns nullptr"); Unlock(); } @@ -213,7 +213,7 @@ VAddr PoolManager::AllocatePool(size_t Size, uint32_t Tag) Entry = reinterpret_cast(g_VMManager.AllocateSystemMemory(PoolType, XBOX_PAGE_READWRITE, PAGE_SIZE, false)); if (Entry == nullptr) { - EmuWarning(LOG_PREFIX " AllocatePool returns nullptr"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "AllocatePool returns nullptr"); Unlock(); RETURN(LOG_PREFIX, reinterpret_cast(Entry)); @@ -267,7 +267,7 @@ void PoolManager::DeallocatePool(VAddr addr) assert((Entry->PoolType & POOL_TYPE_MASK) != 0); if (!IS_POOL_HEADER_MARKED_ALLOCATED(Entry)) { - CxbxKrnlCleanup("Pool at address 0x%X is already free!", addr); + CxbxKrnlCleanup(LOG_PREFIX, "Pool at address 0x%X is already free!", addr); } MARK_POOL_HEADER_FREED(Entry); diff --git a/src/CxbxKrnl/VMManager.cpp b/src/CxbxKrnl/VMManager.cpp index d21132f55..d53954df0 100644 --- a/src/CxbxKrnl/VMManager.cpp +++ b/src/CxbxKrnl/VMManager.cpp @@ -89,7 +89,7 @@ void VMManager::Initialize(HANDLE memory_view, HANDLE pagetables_view, int BootF // the xbe has been tampered with: the entry point and the kernel thunk addresses have been xored with a different key to make it // appear to be of a different type. - CxbxKrnlCleanup("Rebooted xbe type doesn't match with the xbe type that performed the reboot. Tampered xbe or rebooting to the \ + CxbxKrnlCleanup(LOG_PREFIX, "Rebooted xbe type doesn't match with the xbe type that performed the reboot. Tampered xbe or rebooting to the \ dashboard from non-retail xbe?"); } } @@ -178,12 +178,12 @@ dashboard from non-retail xbe?"); } if (g_bIsChihiro) { - printf(LOG_PREFIX " Page table for Chihiro arcade initialized!\n"); + printf("Page table for Chihiro arcade initialized!\n"); } else if (g_bIsDebug) { - printf(LOG_PREFIX " Page table for Debug console initialized!\n"); + printf("Page table for Debug console initialized!\n"); } - else { printf(LOG_PREFIX " Page table for Retail console initialized!\n"); } + else { printf("Page table for Retail console initialized!\n"); } } void VMManager::ConstructMemoryRegion(VAddr Start, size_t Size, MemoryRegionType Type) @@ -434,7 +434,7 @@ void VMManager::ConstructVMA(VAddr Start, size_t Size, MemoryRegionType Type, VM { // Already at the beginning of the map, bail out immediately - EmuWarning(LOG_PREFIX " Can't find any more free space in the memory region %d! Virtual memory exhausted?", Type); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Can't find any more free space in the memory region %d! Virtual memory exhausted?", Type); m_MemoryRegionArray[Type].LastFree = m_MemoryRegionArray[Type].RegionMap.end(); return; } @@ -456,7 +456,7 @@ void VMManager::ConstructVMA(VAddr Start, size_t Size, MemoryRegionType Type, VM // ergo720: I don't expect this to happen since it would mean we have exhausted the virtual space in the memory region, // but it's just in case it does - EmuWarning(LOG_PREFIX " Can't find any more free space in the memory region %d! Virtual memory exhausted?", Type); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Can't find any more free space in the memory region %d! Virtual memory exhausted?", Type); m_MemoryRegionArray[Type].LastFree = m_MemoryRegionArray[Type].RegionMap.end(); @@ -593,7 +593,7 @@ VAddr VMManager::ClaimGpuMemory(size_t Size, size_t* BytesToSkip) } m_NV2AInstanceMemoryBytes = Size; - DbgPrintf("VMEM: MmClaimGpuInstanceMemory : Allocated bytes remaining = 0x%.8X\n", m_NV2AInstanceMemoryBytes); + DbgPrintf(LOG_PREFIX, "MmClaimGpuInstanceMemory : Allocated bytes remaining = 0x%.8X\n", m_NV2AInstanceMemoryBytes); Unlock(); } @@ -640,12 +640,12 @@ void VMManager::PersistMemory(VAddr addr, size_t Size, bool bPersist) if (bPersist) { *(VAddr*)(CONTIGUOUS_MEMORY_BASE + PAGE_SIZE - 4) = addr; - DbgPrintf("KNRL: Persisting LaunchDataPage\n"); + DbgPrintf(LOG_PREFIX, "Persisting LaunchDataPage\n"); } else { *(VAddr*)(CONTIGUOUS_MEMORY_BASE + PAGE_SIZE - 4) = NULL; - DbgPrintf("KNRL: Forgetting LaunchDataPage\n"); + DbgPrintf(LOG_PREFIX, "Forgetting LaunchDataPage\n"); } } else @@ -653,12 +653,12 @@ void VMManager::PersistMemory(VAddr addr, size_t Size, bool bPersist) if (bPersist) { *(VAddr*)(CONTIGUOUS_MEMORY_BASE + PAGE_SIZE - 8) = addr; - DbgPrintf("KNRL: Persisting FrameBuffer\n"); + DbgPrintf(LOG_PREFIX, "Persisting FrameBuffer\n"); } else { *(VAddr*)(CONTIGUOUS_MEMORY_BASE + PAGE_SIZE - 8) = NULL; - DbgPrintf("KNRL: Forgetting FrameBuffer\n"); + DbgPrintf(LOG_PREFIX, "Forgetting FrameBuffer\n"); } } } @@ -726,7 +726,7 @@ void VMManager::RestorePersistentMemory() RestorePersistentAllocation(LauchDataAddress, GetPteAddress(LauchDataAddress)->Hardware.PFN, GetPteAddress(LauchDataAddress)->Hardware.PFN, ContiguousType); - DbgPrintf("VMEM: Restored LaunchDataPage\n"); + DbgPrintf(LOG_PREFIX, "Restored LaunchDataPage\n"); } if (FrameBufferAddress != 0 && IS_PHYSICAL_ADDRESS(FrameBufferAddress)) { @@ -736,7 +736,7 @@ void VMManager::RestorePersistentMemory() RestorePersistentAllocation(FrameBufferAddress, GetPteAddress(FrameBufferAddress)->Hardware.PFN, GetPteAddress(FrameBufferAddress)->Hardware.PFN + (QuerySize(FrameBufferAddress, false) >> PAGE_SHIFT) - 1, ContiguousType); - DbgPrintf("VMEM: Restored FrameBuffer\n"); + DbgPrintf(LOG_PREFIX, "Restored FrameBuffer\n"); } } } @@ -848,7 +848,7 @@ VAddr VMManager::Allocate(size_t Size) VAddr VMManager::AllocateZeroed(size_t Size) { - LOG_FORWARD("g_VMManager.Allocate"); + LOG_FORWARD(LOG_PREFIX, "g_VMManager.Allocate"); VAddr addr = Allocate(Size); if (addr) { xboxkrnl::RtlFillMemoryUlong((void*)addr, ROUND_UP_4K(Size), 0); } @@ -1467,7 +1467,7 @@ size_t VMManager::QuerySize(VAddr addr, bool bCxbxCaller) else if(IS_USER_ADDRESS(addr)) { Type = UserRegion; } else { - DbgPrintf("VMEM: QuerySize: Unknown memory region queried.\n"); + DbgPrintf(LOG_PREFIX, "QuerySize: Unknown memory region queried.\n"); Unlock(); RETURN(LOG_PREFIX, Size); } @@ -1624,7 +1624,7 @@ xboxkrnl::NTSTATUS VMManager::XbAllocateVirtualMemory(VAddr* addr, ULONG ZeroBit if (!ConvertXboxToPteProtection(Protect, &TempPte)) { RETURN(LOG_PREFIX, STATUS_INVALID_PAGE_PROTECTION); } - DbgPrintf("VMEM: XbAllocateVirtualMemory requested range : 0x%.8X - 0x%.8X\n", CapturedBase, CapturedBase + CapturedSize); + DbgPrintf(LOG_PREFIX, "%s requested range : 0x%.8X - 0x%.8X\n", __func__, CapturedBase, CapturedBase + CapturedSize); Lock(); @@ -1691,8 +1691,7 @@ xboxkrnl::NTSTATUS VMManager::XbAllocateVirtualMemory(VAddr* addr, ULONG ZeroBit { // XBOX_MEM_COMMIT was not specified, so we are done with the allocation - DbgPrintf("VMEM: XbAllocateVirtualMemory resulting range : 0x%.8X - 0x%.8X\n", AlignedCapturedBase, - AlignedCapturedBase + AlignedCapturedSize); + DbgPrintf(LOG_PREFIX, "%s resulting range : 0x%.8X - 0x%.8X\n", __func__, AlignedCapturedBase, AlignedCapturedBase + AlignedCapturedSize); *addr = AlignedCapturedBase; *Size = AlignedCapturedSize; @@ -1795,13 +1794,13 @@ xboxkrnl::NTSTATUS VMManager::XbAllocateVirtualMemory(VAddr* addr, ULONG ZeroBit if (!VirtualAlloc((void*)AlignedCapturedBase, AlignedCapturedSize, MEM_COMMIT, (ConvertXboxToWinProtection(PatchXboxPermissions(Protect))) & ~(PAGE_WRITECOMBINE | PAGE_NOCACHE))) { - DbgPrintf("VMEM: XbAllocateVirtualMemory: VirtualAlloc failed to commit the memory! The error was %d\n", GetLastError()); + DbgPrintf(LOG_PREFIX, "%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("VMEM: XBOX_MEM_NOZERO flag is not supported!\n"); } + if (AllocationType & XBOX_MEM_NOZERO) { DbgPrintf(LOG_PREFIX, "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 @@ -1813,8 +1812,7 @@ xboxkrnl::NTSTATUS VMManager::XbAllocateVirtualMemory(VAddr* addr, ULONG ZeroBit XbVirtualProtect(&TempAddr, &TempSize, &TempProtect); } - DbgPrintf("VMEM: XbAllocateVirtualMemory resulting range : 0x%.8X - 0x%.8X\n", AlignedCapturedBase, - AlignedCapturedBase + AlignedCapturedSize); + DbgPrintf(LOG_PREFIX, "%s resulting range : 0x%.8X - 0x%.8X\n", __func__, AlignedCapturedBase, AlignedCapturedBase + AlignedCapturedSize); *addr = AlignedCapturedBase; *Size = AlignedCapturedSize; @@ -1973,7 +1971,7 @@ xboxkrnl::NTSTATUS VMManager::XbFreeVirtualMemory(VAddr* addr, size_t* Size, DWO if (!VirtualFree((void*)AlignedCapturedBase, AlignedCapturedSize, MEM_DECOMMIT)) { - DbgPrintf("VMEM: XbFreeVirtualMemory: VirtualFree failed to decommit the memory! The error was %d\n", GetLastError()); + DbgPrintf(LOG_PREFIX, "%s: VirtualFree failed to decommit the memory! The error was %d\n", __func__, GetLastError()); } } @@ -2331,7 +2329,7 @@ VAddr VMManager::MapMemoryBlock(MappingFn MappingRoutine, MemoryRegionType Type, { // We are already at the beginning of the map, so bail out immediately - EmuWarning(LOG_PREFIX " Failed to map a memory block in the virtual region %d!", Type); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Failed to map a memory block in the virtual region %d!", Type); return NULL; } @@ -2362,7 +2360,7 @@ VAddr VMManager::MapMemoryBlock(MappingFn MappingRoutine, MemoryRegionType Type, // We have failed to map the block. This is likely because the virtual space is fragmented or there are too many // host allocations in the memory region. Log this error and bail out - EmuWarning(LOG_PREFIX " Failed to map a memory block in the virtual region %d!", Type); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Failed to map a memory block in the virtual region %d!", Type); return NULL; } @@ -2464,13 +2462,13 @@ PAddr VMManager::TranslateVAddrToPAddr(const VAddr addr) if (Type != COUNTRegion && Type != ContiguousRegion) { if (IsValidVirtualAddress(addr)) { if (Type == UserRegion) { - EmuWarning("Applying identity mapping hack to allocation at address 0x%X", addr); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Applying identity mapping hack to allocation at address 0x%X", addr); Unlock(); RETURN(LOG_PREFIX, addr); // committed pages in the user region always use VirtualAlloc } VMAIter it = GetVMAIterator(addr, Type); if (it != m_MemoryRegionArray[Type].RegionMap.end() && it->second.type != FreeVma && it->second.bFragmented) { - EmuWarning("Applying identity mapping hack to allocation at address 0x%X", addr); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Applying identity mapping hack to allocation at address 0x%X", addr); Unlock(); RETURN(LOG_PREFIX, addr); // committed pages in the system-devkit regions can use VirtualAlloc because of fragmentation } @@ -2644,7 +2642,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("VMEM: VirtualProtect failed. The error code was %d\n", GetLastError()); + DbgPrintf(LOG_PREFIX, "VirtualProtect failed. The error code was %d\n", GetLastError()); } } @@ -2662,14 +2660,14 @@ VMAIter VMManager::CheckExistenceVMA(VAddr addr, MemoryRegionType Type, size_t S { return it; } - DbgPrintf("VMEM: Located vma but sizes don't match\n"); + DbgPrintf(LOG_PREFIX, "Located vma but sizes don't match\n"); return m_MemoryRegionArray[Type].RegionMap.end(); } return it; } else { - DbgPrintf("VMEM: Vma not found or doesn't start at the supplied address\n"); + DbgPrintf(LOG_PREFIX, "Vma not found or doesn't start at the supplied address\n"); return m_MemoryRegionArray[Type].RegionMap.end(); } } @@ -2717,7 +2715,7 @@ void VMManager::DestructVMA(VAddr addr, MemoryRegionType Type, size_t Size) if (!ret) { - DbgPrintf("VMEM: Deallocation routine failed with error %d\n", GetLastError()); + DbgPrintf(LOG_PREFIX, "Deallocation routine failed with error %d\n", GetLastError()); } } @@ -2743,7 +2741,7 @@ void VMManager::DestructVMA(VAddr addr, MemoryRegionType Type, size_t Size) } else { - DbgPrintf("VMEM: std::prev(CarvedVmaIt) was not free\n"); + DbgPrintf(LOG_PREFIX, "std::prev(CarvedVmaIt) was not free\n"); it = CarvedVmaIt; @@ -2771,7 +2769,7 @@ void VMManager::DestructVMA(VAddr addr, MemoryRegionType Type, size_t Size) --it; } - EmuWarning(LOG_PREFIX " Can't find any more free space in the memory region %d! Virtual memory exhausted?", Type); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Can't find any more free space in the memory region %d! Virtual memory exhausted?", Type); m_MemoryRegionArray[Type].LastFree = m_MemoryRegionArray[Type].RegionMap.end(); diff --git a/src/devices/ADM1032Device.cpp b/src/devices/ADM1032Device.cpp index 3b53ae0a4..2c7cded78 100644 --- a/src/devices/ADM1032Device.cpp +++ b/src/devices/ADM1032Device.cpp @@ -34,10 +34,11 @@ // * // ****************************************************************** +#define LOG_PREFIX CXBXR_MODULE::ADM + #include "ADM1032Device.h" #include "..\CxbxKrnl\Emu.h" // For EmuWarning - void ADM1032Device::Init() { // ergo720: these are the values reported by UnleashX on my modded Xbox after half an hour of playing (in celsius) @@ -51,7 +52,7 @@ uint8_t ADM1032Device::ReadByte(uint8_t command) if (command == 0x0) { return m_MBTemperature; } else if(command == 0x1) { return m_CPUTemperature; } - EmuWarning("Unknown read command sent to the temperature sensor. The command was %d", command); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unknown read command sent to the temperature sensor. The command was %d", command); return 0; } diff --git a/src/devices/EmuNVNet.cpp b/src/devices/EmuNVNet.cpp index 441861a85..8d4eade22 100644 --- a/src/devices/EmuNVNet.cpp +++ b/src/devices/EmuNVNet.cpp @@ -394,7 +394,7 @@ void EmuNVNet_UpdateIRQ() { if (EmuNVNet_GetRegister(NvRegIrqMask, 4) && EmuNVNet_GetRegister(NvRegIrqStatus, 4)) { - DbgPrintf("EmuNVNet: Asserting IRQ\n"); + DbgPrintf(LOG_PREFIX, "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("nvnet mii %s: phy 0x%x %s [0x%x]\n", write ? "write" : "read", phy_addr, EmuNVNet_GetMiiRegisterName(reg), reg); + DbgPrintf(LOG_PREFIX, "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("NET : Read%d: %s (0x%.8X)\n", size, EmuNVNet_GetRegisterName(addr), addr); + DbgPrintf(LOG_PREFIX, "Read%d: %s (0x%.8X)\n", size, EmuNVNet_GetRegisterName(addr), addr); switch (addr) { case NvRegMIIData: @@ -471,8 +471,8 @@ void EmuNVNet_Write(xbaddr addr, uint32_t value, int size) break; case NvRegTxRxControl: if (value == NVREG_TXRXCTL_KICK) { - DbgPrintf("NvRegTxRxControl = NVREG_TXRXCTL_KICK!\n"); - EmuWarning("TODO: nvnet_dma_packet_from_guest"); + DbgPrintf(LOG_PREFIX, "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("NET : Write%d: %s (0x%.8X) = 0x%.8X\n", size, EmuNVNet_GetRegisterName(addr), addr, value); + DbgPrintf(LOG_PREFIX, "Write%d: %s (0x%.8X) = 0x%.8X\n", size, EmuNVNet_GetRegisterName(addr), addr, value); } /* NVNetDevice */ diff --git a/src/devices/SMCDevice.cpp b/src/devices/SMCDevice.cpp index 651469c4d..e12f72fb8 100644 --- a/src/devices/SMCDevice.cpp +++ b/src/devices/SMCDevice.cpp @@ -35,6 +35,8 @@ // ****************************************************************** #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX CXBXR_MODULE::SMC + /* prevent name collisions */ namespace xboxkrnl { @@ -51,7 +53,7 @@ namespace xboxkrnl void SetLEDSequence(LED::Sequence aLEDSequence) { // See http://xboxdevwiki.net/PIC#The_LED - DbgPrintf("SMC : SetLEDSequence : %u\n", (byte)aLEDSequence); + DbgPrintf(LOG_PREFIX, "SetLEDSequence : %u\n", (byte)aLEDSequence); int LedSequence[4] = { XBOX_LED_COLOUR_OFF, XBOX_LED_COLOUR_OFF, XBOX_LED_COLOUR_OFF, XBOX_LED_COLOUR_OFF }; diff --git a/src/devices/Xbox.cpp b/src/devices/Xbox.cpp index 9113619e8..3b23a86cd 100644 --- a/src/devices/Xbox.cpp +++ b/src/devices/Xbox.cpp @@ -60,7 +60,7 @@ MCPXRevision MCPXRevisionFromHardwareModel(HardwareModel hardwareModel) case Revision1_6: return MCPXRevision::MCPX_X3; case DebugKit: - // EmuWarning("Guessing MCPXVersion"); + // EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Guessing MCPXVersion"); return MCPXRevision::MCPX_X2; default: // UNREACHABLE(hardwareModel); @@ -79,7 +79,7 @@ SCMRevision SCMRevisionFromHardwareModel(HardwareModel hardwareModel) case Revision1_4: case Revision1_5: case Revision1_6: - // EmuWarning("Guessing SCMRevision"); + // EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Guessing SCMRevision"); return SCMRevision::P2L; // Assumption; Our SCM returns PIC version string "P05" case DebugKit: return SCMRevision::D01; // Our SCM returns PIC version string "DXB" diff --git a/src/devices/usb/Hub.cpp b/src/devices/usb/Hub.cpp index 67526b41a..dfc43ee11 100644 --- a/src/devices/usb/Hub.cpp +++ b/src/devices/usb/Hub.cpp @@ -36,6 +36,8 @@ #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX CXBXR_MODULE::HUB + // prevent name collisions namespace xboxkrnl { @@ -47,8 +49,6 @@ namespace xboxkrnl #include "CxbxKrnl\EmuKrnl.h" // For EmuWarning #include "Logging.h" -#define LOG_PREFIX CXBXR_MODULE::HUB - #define NUM_PORTS 8 #define PORT_STAT_CONNECTION 0x0001 @@ -249,7 +249,7 @@ int Hub::UsbHubClaimPort(XboxDeviceState* dev, int port) i++; } if (it == m_UsbDev->m_FreePorts.end()) { - EmuWarning("Port requested %d not found (in use?)", port); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Port requested %d not found (in use?)", port); return -1; } dev->Port = *it; @@ -377,8 +377,8 @@ void Hub::UsbHub_HandleControl(XboxDeviceState* dev, USBPacket* p, goto fail; } port = &m_HubState->ports[n]; - DbgPrintf("%s %s GetPortStatus -> Address 0x%X, wIndex %d, wPortStatus %d, wPortChange %d\n", - LOG_STR_HUB, __func__, m_HubState->dev.Addr, index, port->wPortStatus, port->wPortChange); + DbgPrintf(LOG_PREFIX, "%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; data[2] = port->wPortChange; @@ -402,8 +402,8 @@ void Hub::UsbHub_HandleControl(XboxDeviceState* dev, USBPacket* p, USBHubPort* port; XboxDeviceState* dev; - DbgPrintf("%s %s SetPortFeature -> Address 0x%X, wIndex %d, Feature %s\n", - LOG_STR_HUB, __func__, m_HubState->dev.Addr, index, GetFeatureName(value)); + DbgPrintf(LOG_PREFIX, "%s SetPortFeature -> Address 0x%X, wIndex %d, Feature %s\n", + __func__, m_HubState->dev.Addr, index, GetFeatureName(value)); if (n >= NUM_PORTS) { goto fail; @@ -440,8 +440,8 @@ void Hub::UsbHub_HandleControl(XboxDeviceState* dev, USBPacket* p, unsigned int n = index - 1; USBHubPort *port; - DbgPrintf("%s %s ClearPortFeature -> Address 0x%X, wIndex %d, Feature %s\n", - LOG_STR_HUB, __func__, m_HubState->dev.Addr, index, GetFeatureName(value)); + DbgPrintf(LOG_PREFIX, "%s ClearPortFeature -> Address 0x%X, wIndex %d, Feature %s\n", + __func__, m_HubState->dev.Addr, index, GetFeatureName(value)); if (n >= NUM_PORTS) { goto fail; @@ -527,7 +527,7 @@ void Hub::UsbHub_HandleData(XboxDeviceState* dev, USBPacket* p) p->Status = USB_RET_BABBLE; return; } - DbgPrintf("%s %s Address 0x%X, Status %d\n", LOG_STR_HUB, __func__, m_HubState->dev.Addr, status); + DbgPrintf(LOG_PREFIX, "%s Address 0x%X, Status %d\n", __func__, m_HubState->dev.Addr, status); for (i = 0; i < n; i++) { buf[i] = status >> (8 * i); } diff --git a/src/devices/usb/OHCI.cpp b/src/devices/usb/OHCI.cpp index e6defa56c..ff45e084f 100644 --- a/src/devices/usb/OHCI.cpp +++ b/src/devices/usb/OHCI.cpp @@ -34,7 +34,9 @@ // * // ****************************************************************** -#define _XBOXKRNL_DEFEXTRN_ +#define _XBOXKRNL_DEFEXTRN_ + +#define LOG_PREFIX CXBXR_MODULE::OHCI /* prevent name collisions */ namespace xboxkrnl @@ -45,9 +47,7 @@ namespace xboxkrnl #include "OHCI.h" #include "CxbxKrnl\EmuKrnl.h" // For HalSystemInterrupt #include "CxbxCommon.h" -#include "Logging.h" - -#define LOG_PREFIX CXBXR_MODULE::OHCI +#include "Logging.h" /* Define these two if you want to dump usb packets */ //#define DEBUG_ISOCH @@ -249,7 +249,7 @@ void OHCI::OHCI_FrameBoundaryWorker() m_bFrameTime = true; if (OHCI_ReadHCCA(m_Registers.HcHCCA, &hcca)) { - EmuWarning("%s HCCA read error at physical address 0x%X", m_Registers.HcHCCA, LOG_STR_OHCI); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "HCCA read error at physical address 0x%X", m_Registers.HcHCCA); OHCI_FatalError(); m_bFrameTime = false; return; @@ -293,7 +293,7 @@ void OHCI::OHCI_FrameBoundaryWorker() if (!m_Registers.HcDoneHead) { // From the standard: "This is set to zero whenever HC writes the content of this // register to HCCA. It also sets the WritebackDoneHead of HcInterruptStatus." - CxbxKrnlCleanup("%s HcDoneHead is zero but WritebackDoneHead interrupt is not set!\n", LOG_STR_OHCI); + CxbxKrnlCleanup(LOG_PREFIX, "HcDoneHead is zero but WritebackDoneHead interrupt is not set!\n"); } if (m_Registers.HcInterrupt & m_Registers.HcInterruptStatus) { @@ -320,7 +320,7 @@ void OHCI::OHCI_FrameBoundaryWorker() // Writeback HCCA if (OHCI_WriteHCCA(m_Registers.HcHCCA, &hcca)) { - EmuWarning("%s HCCA write error at physical address 0x%X", LOG_STR_OHCI, m_Registers.HcHCCA); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "HCCA write error at physical address 0x%X", m_Registers.HcHCCA); OHCI_FatalError(); } @@ -335,7 +335,7 @@ void OHCI::OHCI_FatalError() OHCI_SetInterrupt(OHCI_INTR_UE); OHCI_BusStop(); - DbgPrintf("%s an unrecoverable error occoured!\n", LOG_STR_OHCI); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "an unrecoverable error occoured!\n"); } bool OHCI::OHCI_ReadHCCA(xbaddr Paddr, OHCI_HCCA* Hcca) @@ -536,7 +536,7 @@ int OHCI::OHCI_ServiceEDlist(xbaddr Head, int Completion) for (current = Head; current; current = next_ed) { if (OHCI_ReadED(current, &ed)) { - EmuWarning("%s ED read error at physical address 0x%X", LOG_STR_OHCI, current); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "ED read error at physical address 0x%X", current); OHCI_FatalError(); return 0; } @@ -614,11 +614,11 @@ 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("Skipping async TD\n"); + DbgPrintf(LOG_PREFIX, "Skipping async TD\n"); return 1; } if (OHCI_ReadTD(addr, &td)) { - EmuWarning("%s TD read error at physical address 0x%X", LOG_STR_OHCI, addr); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "TD read error at physical address 0x%X", addr); OHCI_FatalError(); return 0; } @@ -666,7 +666,7 @@ int OHCI::OHCI_ServiceTD(OHCI_ED* Ed) pid = USB_TOKEN_SETUP; break; default: - EmuWarning("%s bad direction", LOG_STR_OHCI); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "bad direction"); return 1; } @@ -718,7 +718,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("%s too many pending packets\n", LOG_STR_OHCI); + DbgPrintf(LOG_PREFIX, "too many pending packets\n"); return 1; } dev = OHCI_FindDevice(OHCI_BM(Ed->Flags, ED_FA)); @@ -792,29 +792,29 @@ int OHCI::OHCI_ServiceTD(OHCI_ED* Ed) } else { if (ret >= 0) { - DbgPrintf("%s Underrun\n", LOG_STR_OHCI); + DbgPrintf(LOG_PREFIX, "Underrun\n"); OHCI_SET_BM(td.Flags, TD_CC, OHCI_CC_DATAUNDERRUN); } else { switch (ret) { case USB_RET_IOERROR: case USB_RET_NODEV: - DbgPrintf("%s Received DEV ERROR\n", LOG_STR_OHCI); + DbgPrintf(LOG_PREFIX, "Received DEV ERROR\n", ); OHCI_SET_BM(td.Flags, TD_CC, OHCI_CC_DEVICENOTRESPONDING); break; case USB_RET_NAK: - DbgPrintf("%s Received NAK\n", LOG_STR_OHCI); + DbgPrintf(LOG_PREFIX, "Received NAK\n"); return 1; case USB_RET_STALL: - DbgPrintf("%s Received STALL\n", LOG_STR_OHCI); + DbgPrintf(LOG_PREFIX, "Received STALL\n"); OHCI_SET_BM(td.Flags, TD_CC, OHCI_CC_STALL); break; case USB_RET_BABBLE: - DbgPrintf("%s Received BABBLE\n", LOG_STR_OHCI); + DbgPrintf(LOG_PREFIX, "Received BABBLE\n"); OHCI_SET_BM(td.Flags, TD_CC, OHCI_CC_DATAOVERRUN); break; default: - DbgPrintf("%s Bad device response %d\n", LOG_STR_OHCI, ret); + DbgPrintf(LOG_PREFIX, "Bad device response %d\n", ret); OHCI_SET_BM(td.Flags, TD_CC, OHCI_CC_UNDEXPETEDPID); OHCI_SET_BM(td.Flags, TD_EC, 3); } @@ -911,7 +911,7 @@ void OHCI::OHCI_StateReset() OHCI_StopEndpoints(); - DbgPrintf("%s Reset mode event.\n", LOG_STR_OHCI); + DbgPrintf(LOG_PREFIX, "Reset mode event.\n"); } void OHCI::OHCI_BusStart() @@ -919,7 +919,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("%s Operational mode event\n", LOG_STR_OHCI); + DbgPrintf(LOG_PREFIX, "Operational mode event\n"); // SOF event OHCI_SOF(true); @@ -966,11 +966,11 @@ void OHCI::OHCI_ChangeState(uint32_t Value) case Suspend: OHCI_BusStop(); - DbgPrintf("%s Suspend mode event\n", LOG_STR_OHCI); + DbgPrintf(LOG_PREFIX, "Suspend mode event\n"); break; case Resume: - DbgPrintf("%s Resume mode event\n", LOG_STR_OHCI); + DbgPrintf(LOG_PREFIX, "Resume mode event\n"); break; case Reset: @@ -978,7 +978,7 @@ void OHCI::OHCI_ChangeState(uint32_t Value) break; default: - EmuWarning("%s Unknown USB mode!", LOG_STR_OHCI); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unknown USB mode!"); } } @@ -997,7 +997,7 @@ uint32_t OHCI::OHCI_ReadRegister(xbaddr Addr) if (Addr & 3) { // The standard allows only aligned reads to the registers - DbgPrintf("%s Unaligned read. Ignoring.\n", LOG_STR_OHCI); + DbgPrintf(LOG_PREFIX, "Unaligned read. Ignoring.\n"); return ret; } else { @@ -1102,7 +1102,7 @@ uint32_t OHCI::OHCI_ReadRegister(xbaddr Addr) break; default: - EmuWarning("%s Read register operation with bad offset %u. Ignoring.", LOG_STR_OHCI, Addr >> 2); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Read register operation with bad offset %u. Ignoring.", Addr >> 2); } return ret; } @@ -1112,7 +1112,7 @@ void OHCI::OHCI_WriteRegister(xbaddr Addr, uint32_t Value) { if (Addr & 3) { // The standard allows only aligned writes to the registers - DbgPrintf("%s Unaligned write. Ignoring.\n", LOG_STR_OHCI); + DbgPrintf(LOG_PREFIX, "Unaligned write. Ignoring.\n"); return; } else { @@ -1189,7 +1189,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("%s Changing frame interval duration. New value is %u\n", LOG_STR_OHCI, Value & OHCI_FMI_FI); + DbgPrintf(LOG_PREFIX, "Changing frame interval duration. New value is %u\n", Value & OHCI_FMI_FI); } m_Registers.HcFmInterval = Value & ~0xC000; } @@ -1241,7 +1241,7 @@ void OHCI::OHCI_WriteRegister(xbaddr Addr, uint32_t Value) break; default: - EmuWarning("%s Write register operation with bad offset %u. Ignoring.", LOG_STR_OHCI, Addr >> 2); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Write register operation with bad offset %u. Ignoring.", Addr >> 2); } } } @@ -1317,7 +1317,7 @@ void OHCI::OHCI_SetHubStatus(uint32_t Value) for (i = 0; i < 4; i++) { OHCI_PortPower(i, 0); } - DbgPrintf("%s powered down all ports\n", LOG_STR_OHCI); + DbgPrintf(LOG_PREFIX, "powered down all ports\n"); } if (Value & OHCI_RHS_LPSC) { @@ -1326,7 +1326,7 @@ void OHCI::OHCI_SetHubStatus(uint32_t Value) for (i = 0; i < 4; i++) { OHCI_PortPower(i, 1); } - DbgPrintf("%s powered up all ports\n", LOG_STR_OHCI); + DbgPrintf(LOG_PREFIX, "powered up all ports\n"); } if (Value & OHCI_RHS_DRWE) { @@ -1375,11 +1375,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("%s port %d: SUSPEND\n", LOG_STR_OHCI, PortNum); + DbgPrintf(LOG_PREFIX, "port %d: SUSPEND\n", PortNum); } if (OHCI_PortSetIfConnected(PortNum, Value & OHCI_PORT_PRS)) { - DbgPrintf("%s port %d: RESET\n", LOG_STR_OHCI, PortNum); + DbgPrintf(LOG_PREFIX, "port %d: RESET\n", PortNum); m_UsbDevice->USB_DeviceReset(port->UsbPort.Dev); port->HcRhPortStatus &= ~OHCI_PORT_PRS; // ??? Should this also set OHCI_PORT_PESC @@ -1447,7 +1447,7 @@ void OHCI::OHCI_Detach(USBPort* Port) port->HcRhPortStatus |= OHCI_PORT_PESC; } - DbgPrintf("%s Detached port %d\n", LOG_STR_OHCI, Port->PortIndex); + DbgPrintf(LOG_PREFIX, "Detached port %d\n", Port->PortIndex); if (old_state != port->HcRhPortStatus) { OHCI_SetInterrupt(OHCI_INTR_RHSC); @@ -1475,7 +1475,7 @@ void OHCI::OHCI_Attach(USBPort* Port) OHCI_SetInterrupt(OHCI_INTR_RD); } - DbgPrintf("%s Attached port %d\n", LOG_STR_OHCI, Port->PortIndex); + DbgPrintf(LOG_PREFIX, "Attached port %d\n", Port->PortIndex); if (old_state != port->HcRhPortStatus) { OHCI_SetInterrupt(OHCI_INTR_RHSC); @@ -1492,14 +1492,14 @@ void OHCI::OHCI_Wakeup(USBPort* port1) OHCIPort* port = &m_Registers.RhPort[port1->PortIndex]; uint32_t intr = 0; if (port->HcRhPortStatus & OHCI_PORT_PSS) { - DbgPrintf("%s port %d: wakeup\n", LOG_STR_OHCI, port1->PortIndex); + 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("%s remote-wakeup: SUSPEND->RESUME\n", LOG_STR_OHCI); + 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." @@ -1534,8 +1534,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("%s head 0x%X, current 0x%X\n", - LOG_STR_OHCI, m_Registers.HcControlHeadED, m_Registers.HcControlCurrentED); + DbgPrintf(LOG_PREFIX, "head 0x%X, current 0x%X\n", m_Registers.HcControlHeadED, m_Registers.HcControlCurrentED); } if (!OHCI_ServiceEDlist(m_Registers.HcControlHeadED, completion)) { m_Registers.HcControlCurrentED = 0; @@ -1575,7 +1574,7 @@ int OHCI::OHCI_ServiceIsoTD(OHCI_ED* ed, int completion) addr = ed->HeadP & OHCI_DPTR_MASK; if (OHCI_ReadIsoTD(addr, &iso_td)) { - DbgPrintf("%s ISO_TD read error at physical address 0x%X\n", LOG_STR_OHCI, addr); + DbgPrintf(LOG_PREFIX, "ISO_TD read error at physical address 0x%X\n", addr); OHCI_FatalError(); return 0; } @@ -1606,13 +1605,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("%s ISO_TD R=%d < 0\n", LOG_STR_OHCI, relative_frame_number); + DbgPrintf(LOG_PREFIX, "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("%s ISO_TD R=%d > FC=%d\n", LOG_STR_OHCI, relative_frame_number, frame_count); + DbgPrintf(LOG_PREFIX, "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); @@ -1653,12 +1652,12 @@ int OHCI::OHCI_ServiceIsoTD(OHCI_ED* ed, int completion) pid = USB_TOKEN_SETUP; break; default: - EmuWarning("%s Bad direction %d", LOG_STR_OHCI, dir); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Bad direction %d", dir); return 1; } if (!iso_td.BufferPage0 || !iso_td.BufferEnd) { - DbgPrintf("%s ISO_TD bp 0x%.8X be 0x%.8X\n", LOG_STR_OHCI, iso_td.BufferPage0, iso_td.BufferEnd); + DbgPrintf(LOG_PREFIX, "ISO_TD bp 0x%.8X be 0x%.8X\n", iso_td.BufferPage0, iso_td.BufferEnd); return 1; } @@ -1676,12 +1675,12 @@ 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("%s ISO_TD cc != not accessed 0x%.8x 0x%.8x\n", LOG_STR_OHCI, start_offset, next_offset); + DbgPrintf(LOG_PREFIX, "ISO_TD cc != not accessed 0x%.8x 0x%.8x\n", start_offset, next_offset); return 1; } if ((relative_frame_number < frame_count) && (start_offset > next_offset)) { - printf("%s ISO_TD start_offset=0x%.8x > next_offset=0x%.8x\n", LOG_STR_OHCI, start_offset, next_offset); + printf("%s ISO_TD start_offset=0x%.8x > next_offset=0x%.8x\n", start_offset, next_offset); return 1; } @@ -1779,12 +1778,12 @@ int OHCI::OHCI_ServiceIsoTD(OHCI_ED* ed, int completion) else { // Handle the error condition if (ret > static_cast(len)) { // Sequence Error - DbgPrintf("%s DataOverrun %d > %zu\n", LOG_STR_OHCI, ret, len); + DbgPrintf(LOG_PREFIX, "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("%s DataUnderrun %d\n", LOG_STR_OHCI, ret); + DbgPrintf(LOG_PREFIX, "DataUnderrun %d\n", ret); OHCI_SET_BM(iso_td.Offset[relative_frame_number], TD_PSW_CC, OHCI_CC_DATAUNDERRUN); } else { @@ -1796,12 +1795,12 @@ int OHCI::OHCI_ServiceIsoTD(OHCI_ED* ed, int completion) break; case USB_RET_NAK: // NAK and STALL case USB_RET_STALL: - DbgPrintf("%s got NAK/STALL %d\n", LOG_STR_OHCI, ret); + DbgPrintf(LOG_PREFIX, "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("%s Bad device response %d\n", LOG_STR_OHCI, ret); + DbgPrintf(LOG_PREFIX, "Bad device response %d\n", ret); OHCI_SET_BM(iso_td.Offset[relative_frame_number], TD_PSW_CC, OHCI_CC_UNDEXPETEDPID); break; } diff --git a/src/devices/usb/USBDevice.cpp b/src/devices/usb/USBDevice.cpp index bc086245c..617ac79dd 100644 --- a/src/devices/usb/USBDevice.cpp +++ b/src/devices/usb/USBDevice.cpp @@ -34,7 +34,9 @@ // * // ****************************************************************** -#define _XBOXKRNL_DEFEXTRN_ +#define _XBOXKRNL_DEFEXTRN_ + +#define LOG_PREFIX CXBXR_MODULE::USB // prevent name collisions namespace xboxkrnl @@ -48,8 +50,6 @@ namespace xboxkrnl #include "CxbxCommon.h" #include "Logging.h" -#define LOG_PREFIX CXBXR_MODULE::USB - #define SETUP_STATE_IDLE 0 #define SETUP_STATE_SETUP 1 #define SETUP_STATE_DATA 2 @@ -283,7 +283,7 @@ void USBDevice::USB_PacketCheckState(USBPacket* p, USBPacketState expected) return; } - EmuWarning("%s: packet state check failed!", LOG_STR_USB); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "packet state check failed!"); assert(0); } @@ -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("%s: ctrl buffer too small (%d > %zu)\n", LOG_STR_USB, s->SetupLength, sizeof(s->DataBuffer)); + DbgPrintf(LOG_PREFIX, "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("%s: ctrl buffer too small (%d > %zu)\n", LOG_STR_USB, s->SetupLength, sizeof(s->DataBuffer)); + DbgPrintf(LOG_PREFIX, "ctrl buffer too small (%d > %zu)\n", s->SetupLength, sizeof(s->DataBuffer)); p->Status = USB_RET_STALL; return; } @@ -522,7 +522,7 @@ void USBDevice::USB_PacketCopy(USBPacket* p, void* ptr, size_t bytes) IoVecFromBuffer(iov->IoVecStruct, iov->IoVecNumber, p->ActualLength, ptr, bytes); break; default: - CxbxKrnlCleanup("%s: %s has an invalid pid: %x\n", LOG_STR_USB, __func__, p->Pid); + CxbxKrnlCleanup(LOG_PREFIX, "%s has an invalid pid: %x\n", __func__, p->Pid); } p->ActualLength += bytes; } @@ -780,7 +780,7 @@ void USBDevice::USBDesc_SetDefaults(XboxDeviceState* dev) break; } default: - EmuWarning("%s: unknown speed parameter %d set in %s", LOG_STR_USB, dev->ProductDesc.c_str()); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "unknown speed parameter %d set in %s", dev->Speed, dev->ProductDesc.c_str()); } USBDesc_SetConfig(dev, 0); } @@ -899,7 +899,7 @@ int USBDevice::USBDesc_HandleControl(XboxDeviceState* dev, USBPacket *p, // 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("%s: address 0x%X set for device %s\n", LOG_STR_USB, dev->Addr, dev->ProductDesc.c_str()); + DbgPrintf(LOG_PREFIX, "address 0x%X set for device %s\n", dev->Addr, dev->ProductDesc.c_str()); ret = 0; break; } @@ -925,8 +925,8 @@ int USBDevice::USBDesc_HandleControl(XboxDeviceState* dev, USBPacket *p, // 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("%s: received standard SetConfiguration() request for device at address 0x%X. Configuration selected is %d and returned %d\n", - LOG_STR_USB, dev->Addr, value, ret); + 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; } @@ -959,8 +959,8 @@ int USBDevice::USBDesc_HandleControl(XboxDeviceState* dev, USBPacket *p, dev->RemoteWakeup = 0; ret = 0; } - DbgPrintf("%s: received standard ClearFeature() request for device at address 0x%X. Feature selected is %d and returned %d\n", - LOG_STR_USB, dev->Addr, value, ret); + 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; } @@ -971,8 +971,8 @@ int USBDevice::USBDesc_HandleControl(XboxDeviceState* dev, USBPacket *p, dev->RemoteWakeup = 1; ret = 0; } - DbgPrintf("%s: received standard SetFeature() request for device at address 0x%X. Feature selected is %d and returned %d\n", - LOG_STR_USB, dev->Addr, value, ret); + 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; } @@ -992,8 +992,8 @@ int USBDevice::USBDesc_HandleControl(XboxDeviceState* dev, USBPacket *p, // 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("%s: received standard SetInterface() request for device at address 0x%X. Interface selected is %d, Alternative Setting \ -is %d and returned %d\n", LOG_STR_USB, dev->Addr, index, value, ret); + 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; } @@ -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("%s: read operation of device descriptor of device 0x%X returns %d\n", LOG_STR_USB, dev->Addr, ret); + DbgPrintf(LOG_PREFIX, "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("%s: read operation of configuration descriptor %d of device 0x%X returns %d\n", LOG_STR_USB, index, dev->Addr, ret); + DbgPrintf(LOG_PREFIX, "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("%s: read operation of string descriptor %d of device 0x%X returns %d\n", LOG_STR_USB, index, dev->Addr, ret); + DbgPrintf(LOG_PREFIX, "read operation of string descriptor %d of device 0x%X returns %d\n", index, dev->Addr, ret); break; } @@ -1042,7 +1042,7 @@ int USBDevice::USBDesc_HandleStandardGetDescriptor(XboxDeviceState* dev, USBPack // USB_DT_BOS (15) and USB_DT_DEBUG (10) -> usb 3.0 only default: - EmuWarning("%s: %s has a device address %d of unknown type %d (len %zd)", LOG_STR_USB, __func__, dev->Addr, type, len); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "%s has a device address %d of unknown type %d (len %zd)", __func__, dev->Addr, type, len); break; } diff --git a/src/devices/usb/XidGamepad.cpp b/src/devices/usb/XidGamepad.cpp index 7fec4ab32..6b41d3168 100644 --- a/src/devices/usb/XidGamepad.cpp +++ b/src/devices/usb/XidGamepad.cpp @@ -34,7 +34,9 @@ // * // ****************************************************************** -#define _XBOXKRNL_DEFEXTRN_ +#define _XBOXKRNL_DEFEXTRN_ + +#define LOG_PREFIX CXBXR_MODULE::XIDCTRL // prevent name collisions namespace xboxkrnl @@ -48,9 +50,7 @@ namespace xboxkrnl #include "Common/Input/SDL2_Device.h" #include "OHCI.h" #include "CxbxKrnl\EmuKrnl.h" // For EmuWarning -#include "Logging.h" - -#define LOG_PREFIX CXBXR_MODULE::XIDCTRL +#include "Logging.h" #define USB_CLASS_XID 0x58 #define USB_DT_XID 0x42 @@ -263,7 +263,7 @@ int XidGamepad::UsbXidClaimPort(XboxDeviceState* dev, int port) i++; } if (it == m_UsbDev->m_FreePorts.end()) { - EmuWarning("Port requested %d.2 not found (in use?)", port); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Port requested %d.2 not found (in use?)", port); return -1; } @@ -330,7 +330,7 @@ void XidGamepad::UsbXid_Attach(XboxDeviceState* dev) void XidGamepad::UsbXid_HandleReset() { - DbgPrintf("%s reset event\n", LOG_STR_GAMEPAD); + DbgPrintf(LOG_PREFIX, "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("%s handled by USBDesc_HandleControl, ret is %d\n", LOG_STR_GAMEPAD, ret); + DbgPrintf(LOG_PREFIX, "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("%s GET_REPORT 0x%X\n", LOG_STR_GAMEPAD, value); + DbgPrintf(LOG_PREFIX, "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("%s SET_REPORT 0x%X\n", LOG_STR_GAMEPAD, value); + DbgPrintf(LOG_PREFIX, "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("%s GET_DESCRIPTOR 0x%x\n", LOG_STR_GAMEPAD, value); + DbgPrintf(LOG_PREFIX, "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("%s XID_GET_CAPABILITIES 0x%x\n", LOG_STR_GAMEPAD, value); + DbgPrintf(LOG_PREFIX, "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("%s unknown xpad request 0x%X: value = 0x%X\n", LOG_STR_GAMEPAD, request, value); + DbgPrintf(LOG_PREFIX, "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("%s unknown xpad request 0x%X: value = 0x%X\n", LOG_STR_GAMEPAD, request, value); + DbgPrintf(LOG_PREFIX, "unknown xpad request 0x%X: value = 0x%X\n", request, value); std::memset(data, 0x00, length); p->Status = USB_RET_STALL; break; } default: - DbgPrintf("%s USB stalled on request 0x%X value 0x%X\n", LOG_STR_GAMEPAD, request, value); + DbgPrintf(LOG_PREFIX, "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("Set rumble power to left: 0x%X and right: 0x%X\n", + DbgPrintf(LOG_PREFIX, "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); } diff --git a/src/devices/video/EmuNV2A_PGRAPH.cpp b/src/devices/video/EmuNV2A_PGRAPH.cpp index 8c7432bff..d567f5043 100644 --- a/src/devices/video/EmuNV2A_PGRAPH.cpp +++ b/src/devices/video/EmuNV2A_PGRAPH.cpp @@ -637,7 +637,7 @@ static void pgraph_handle_method(NV2AState *d, context_surfaces_2d->dest_offset = parameter & 0x07FFFFFF; break; default: - EmuWarning("NV2A: Unknown NV_CONTEXT_SURFACES_2D Method: 0x%08X\n", method); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unknown NV_CONTEXT_SURFACES_2D Method: 0x%08X\n", method); } break; @@ -730,7 +730,7 @@ static void pgraph_handle_method(NV2AState *d, break; default: - EmuWarning("NV2A: Unknown NV_IMAGE_BLIT Method: 0x%08X\n", method); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Unknown NV_IMAGE_BLIT Method: 0x%08X\n", method); } break; } diff --git a/src/devices/video/EmuNV2A_PRMCIO.cpp b/src/devices/video/EmuNV2A_PRMCIO.cpp index abd460f03..efc6a1f91 100644 --- a/src/devices/video/EmuNV2A_PRMCIO.cpp +++ b/src/devices/video/EmuNV2A_PRMCIO.cpp @@ -93,14 +93,14 @@ DEVICE_WRITE32(PRMCIO) if (d->prmcio.cr_index == VGA_CRTC_OVERFLOW) { d->prmcio.cr[VGA_CRTC_OVERFLOW] = (d->prmcio.cr[VGA_CRTC_OVERFLOW] & ~0x10) | (value & 0x10); - EmuWarning("TODO: vbe_update_vgaregs"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "TODO: vbe_update_vgaregs"); //vbe_update_vgaregs(); } return; } d->prmcio.cr[d->prmcio.cr_index] = value; - EmuWarning("TODO: vbe_update_vgaregs"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "TODO: vbe_update_vgaregs"); //vbe_update_vgaregs(); switch (d->prmcio.cr_index) { @@ -112,7 +112,7 @@ DEVICE_WRITE32(PRMCIO) case VGA_CRTC_V_SYNC_END: case VGA_CRTC_MODE: // TODO: s->update_retrace_info(s); - EmuWarning("TODO: update_retrace_info"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "TODO: update_retrace_info"); break; } break; diff --git a/src/devices/video/nv2a.cpp b/src/devices/video/nv2a.cpp index b22d104d2..9636720c7 100644 --- a/src/devices/video/nv2a.cpp +++ b/src/devices/video/nv2a.cpp @@ -164,11 +164,11 @@ static void update_irq(NV2AState *d) #include "EmuNV2A_DEBUG.cpp" -#define DEBUG_READ32(DEV) DbgPrintf("X86 : Rd32 NV2A " #DEV "(0x%08X) = 0x%08X [Handled %s]\n", addr, result, DebugNV_##DEV##(addr)) -#define DEBUG_READ32_UNHANDLED(DEV) { DbgPrintf("X86 : Rd32 NV2A " #DEV "(0x%08X) = 0x%08X [Unhandled %s]\n", addr, result, DebugNV_##DEV##(addr)); return result; } +#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_WRITE32(DEV) DbgPrintf("X86 : Wr32 NV2A " #DEV "(0x%08X, 0x%08X) [Handled %s]\n", addr, value, DebugNV_##DEV##(addr)) -#define DEBUG_WRITE32_UNHANDLED(DEV) { DbgPrintf("X86 : Wr32 NV2A " #DEV "(0x%08X, 0x%08X) [Unhandled %s]\n", addr, value, DebugNV_##DEV##(addr)); return; } +#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 DEVICE_READ32(DEV) uint32_t EmuNV2A_##DEV##_Read32(NV2AState *d, xbaddr addr) #define DEVICE_READ32_SWITCH() uint32_t result = 0; switch (addr) @@ -987,7 +987,7 @@ void cxbx_gl_render_overlays(NV2AState *d) // Detect some special cases, for later finetuning if (overlay_in_s != 0 || overlay_in_t != 0 || !overlay.covers_framebuffer) { - LOG_TEST_CASE("Non-standard overlay dimensions"); + LOG_TEST_CASE(LOG_PREFIX, "Non-standard overlay dimensions"); } // Convert UV coordinates to [0.0, 1.0] @@ -1153,7 +1153,7 @@ void CxbxReserveNV2AMemory(NV2AState *d) MEM_RESERVE, // Don't allocate actual physical storage in memory PAGE_NOACCESS); // Any access must result in an access violation exception (handled in EmuException/EmuX86_DecodeException) if (memory == NULL) { - EmuWarning("Couldn't reserve NV2A memory, continuing assuming we'll receive (and handle) access violation exceptions anyway..."); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Couldn't reserve NV2A memory, continuing assuming we'll receive (and handle) access violation exceptions anyway..."); return; } @@ -1169,7 +1169,7 @@ void CxbxReserveNV2AMemory(NV2AState *d) MEM_COMMIT, // No MEM_RESERVE | PAGE_READWRITE); if (d->pramin.ramin_ptr == NULL) { - EmuWarning("Couldn't allocate NV2A PRAMIN memory"); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "Couldn't allocate NV2A PRAMIN memory"); return; } @@ -1303,7 +1303,7 @@ uint32_t NV2ADevice::MMIORead(int barIndex, uint32_t addr, unsigned size) } } - EmuWarning("NV2ADevice::MMIORead: Unhandled barIndex %d, addr %08X, size %d", barIndex, addr, size); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NV2ADevice::MMIORead: Unhandled barIndex %d, addr %08X, size %d", barIndex, addr, size); return 0; } @@ -1370,5 +1370,5 @@ void NV2ADevice::MMIOWrite(int barIndex, uint32_t addr, uint32_t value, unsigned } } - EmuWarning("NV2ADevice::MMIOWrite: Unhandled barIndex %d, addr %08X, value %08X, size %d", barIndex, addr, value, size); + EmuLog(LOG_PREFIX, LOG_LEVEL::WARNING, "NV2ADevice::MMIOWrite: Unhandled barIndex %d, addr %08X, value %08X, size %d", barIndex, addr, value, size); }