diff --git a/src/common/Settings.cpp b/src/common/Settings.cpp index 2fc41acef..6b082b6d6 100644 --- a/src/common/Settings.cpp +++ b/src/common/Settings.cpp @@ -33,7 +33,6 @@ #include "core\kernel\support\Emu.h" #include "EmuShared.h" #include -#include "common\input\InputManager.h" #include "common\input\layout_xbox_device.h" #include #include "common/util/cliConfig.hpp" diff --git a/src/common/Settings.hpp b/src/common/Settings.hpp index e11f4c829..d24a6f755 100644 --- a/src/common/Settings.hpp +++ b/src/common/Settings.hpp @@ -29,7 +29,7 @@ #include "Cxbx.h" #include "SimpleIni.h" -#include "input\InputDevice.h" +#include "common\input\InputManager.h" #include "common\util\CxbxUtil.h" #include #include @@ -147,7 +147,7 @@ public: struct s_input_port { int Type; - int SlotType[2]; + int SlotType[XBOX_CTRL_NUM_SLOTS]; std::string DeviceName; std::string ProfileName; }; diff --git a/src/common/input/Button.h b/src/common/input/Button.h index efd71b959..a74afded5 100644 --- a/src/common/input/Button.h +++ b/src/common/input/Button.h @@ -35,8 +35,6 @@ #define SBC_NUM_BUTTONS 56 #define HIGHEST_NUM_BUTTONS SBC_NUM_BUTTONS -#define XBOX_CTRL_NUM_SLOTS 2 - #define XBOX_BUTTON_NAME_LENGTH 30 #define HOST_BUTTON_NAME_LENGTH 30 diff --git a/src/common/input/InputDevice.cpp b/src/common/input/InputDevice.cpp index 2d2596483..aa63b6dc7 100644 --- a/src/common/input/InputDevice.cpp +++ b/src/common/input/InputDevice.cpp @@ -33,6 +33,7 @@ // https://github.com/dolphin-emu/dolphin #include "InputDevice.h" +#include "InputManager.h" #include "common\util\CxbxUtil.h" #include #include @@ -93,22 +94,22 @@ std::string GetInputDeviceName(int dev_type) std::string PortUserFormat(std::string_view port) { - int port1, slot; - PortStr2Int(port, &port1, &slot); - ++port1; + int port_num, slot; + PortStr2Int(port, &port_num, &slot); + ++port_num; if (slot != PORT_INVALID) { ++slot; - return std::to_string(port1) + "." + std::to_string(slot); + return std::to_string(port_num) + "." + std::to_string(slot); } else { - return std::to_string(port1); + return std::to_string(port_num); } } -void PortStr2Int(std::string_view port, int *port1, int *slot) +void PortStr2Int(std::string_view port, int *port_num, int *slot) { *slot = PORT_INVALID; - auto &ret = std::from_chars(port.data(), port.data() + port.size(), *port1); + auto &ret = std::from_chars(port.data(), port.data() + port.size(), *port_num); assert(ret.ec != std::errc::invalid_argument); if (ret.ptr != port.data() + port.size()) { ++ret.ptr; @@ -161,8 +162,8 @@ const std::vector InputDevice::GetIoControls() const auto InputDevice::FindPort(std::string_view Port) const { - return std::find_if(m_XboxPort.begin(), m_XboxPort.end(), [Port](std::string_view Port1) { - if (Port1 == Port) { + return std::find_if(m_XboxPort.begin(), m_XboxPort.end(), [Port](std::string_view CurrPort) { + if (CurrPort == Port) { return true; } return false; diff --git a/src/common/input/InputDevice.h b/src/common/input/InputDevice.h index a56ab1f9b..18323d8b8 100644 --- a/src/common/input/InputDevice.h +++ b/src/common/input/InputDevice.h @@ -36,12 +36,6 @@ #include #include "SDL.h" -#define PORT_INVALID -1 -#define PORT_1 0 -#define PORT_2 1 -#define PORT_3 2 -#define PORT_4 3 - #define DIRECTION_IN 0 #define DIRECTION_OUT 1 @@ -69,15 +63,13 @@ XBOX_INPUT_DEVICE; inline bool g_bIsTrackingMoLeave = false; inline bool g_bIsTrackingMoMove = false; -// Lookup array used to translate a gui port to an xbox usb port and vice versa -extern int Gui2XboxPortArray[4]; // Retrieves the printable name of a xid type std::string GetInputDeviceName(int dev_type); // Converts the port number in the user format std::string PortUserFormat(std::string_view); // Extracts port and slot number from a port formatted as a string -void PortStr2Int(std::string_view port, int *port1, int *slot); +void PortStr2Int(std::string_view port, int *port_num, int *slot); /* Abstract class which represents a host device usable for input/output */ class InputDevice diff --git a/src/common/input/InputManager.cpp b/src/common/input/InputManager.cpp index 9c42093bb..894d32356 100644 --- a/src/common/input/InputManager.cpp +++ b/src/common/input/InputManager.cpp @@ -52,12 +52,6 @@ // hle input specific #include "core\hle\XAPI\Xapi.h" -int Gui2XboxPortArray[4] = { - 3, - 4, - 1, - 2 -}; int dev_num_buttons[to_underlying(XBOX_INPUT_DEVICE::DEVICE_MAX)] = { XBOX_CTRL_NUM_BUTTONS, // MS_CONTROLLER_DUKE @@ -95,13 +89,13 @@ void InputDeviceManager::Initialize(bool is_gui, HWND hwnd) }); m_Cv.wait(lck, []() { - return (Sdl::SdlInitStatus != Sdl::SDL_NOT_INIT) && - (XInput::XInputInitStatus != XInput::XINPUT_NOT_INIT) && - (RawInput::RawInputInitStatus != RawInput::RAWINPUT_NOT_INIT); + return (Sdl::InitStatus != Sdl::NOT_INIT) && + (XInput::InitStatus != XInput::NOT_INIT) && + (RawInput::InitStatus != RawInput::NOT_INIT); }); lck.unlock(); - if (Sdl::SdlInitStatus < 0 || XInput::XInputInitStatus < 0 || RawInput::RawInputInitStatus < 0) { + if (Sdl::InitStatus < 0 || XInput::InitStatus < 0 || RawInput::InitStatus < 0) { CxbxKrnlCleanup("Failed to initialize input subsystem! Consult debug log for more information"); } @@ -109,12 +103,12 @@ void InputDeviceManager::Initialize(bool is_gui, HWND hwnd) RefreshDevices(); if (!is_gui) { - for (unsigned i = 0; i < 12; ++i) { + for (unsigned i = 0; i < MAX_DEVS; ++i) { g_devs[i].type = XBOX_INPUT_DEVICE::DEVICE_INVALID; g_devs[i].port = std::to_string(PORT_INVALID); } - for (unsigned i = 0; i < 4; ++i) { + for (unsigned i = 0; i < XBOX_NUM_PORTS; ++i) { int type; g_EmuShared->GetInputDevTypeSettings(&type, i); if (type != to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)) { @@ -225,31 +219,31 @@ void InputDeviceManager::RemoveDevice(std::function Ca void InputDeviceManager::UpdateDevices(std::string_view port, bool ack) { DeviceState *dev, *upstream; - int port1, slot, type; - PortStr2Int(port, &port1, &slot); - dev = &g_devs[port1]; + int port_num, slot, type; + PortStr2Int(port, &port_num, &slot); + dev = &g_devs[port_num]; if (slot == PORT_INVALID) { // Port references a device attached to an xbox port upstream = nullptr; - g_EmuShared->GetInputDevTypeSettings(&type, port1); + g_EmuShared->GetInputDevTypeSettings(&type, port_num); } else { // Port references a device attached to a slot port upstream = dev; dev = dev->slots[slot]; - g_EmuShared->GetInputSlotTypeSettings(&type, port1, slot); + g_EmuShared->GetInputSlotTypeSettings(&type, port_num, slot); } // updating a slot if (dev == nullptr) { // connect slot if (type != to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID) && - g_devs[MU_OFFSET + (XBOX_CTRL_NUM_SLOTS * port1) + slot].type == XBOX_INPUT_DEVICE::DEVICE_INVALID) { - ConnectDevice(&g_devs[MU_OFFSET + (XBOX_CTRL_NUM_SLOTS * port1) + slot], upstream, type, port); + g_devs[MU_OFFSET + (XBOX_CTRL_NUM_SLOTS * port_num) + slot].type == XBOX_INPUT_DEVICE::DEVICE_INVALID) { + ConnectDevice(&g_devs[MU_OFFSET + (XBOX_CTRL_NUM_SLOTS * port_num) + slot], upstream, type, port); } // disconnect slot else if (type == to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID) && - g_devs[MU_OFFSET + (XBOX_CTRL_NUM_SLOTS * port1) + slot].type != XBOX_INPUT_DEVICE::DEVICE_INVALID) { - DisconnectDevice(&g_devs[MU_OFFSET + (XBOX_CTRL_NUM_SLOTS * port1) + slot], port, ack); + g_devs[MU_OFFSET + (XBOX_CTRL_NUM_SLOTS * port_num) + slot].type != XBOX_INPUT_DEVICE::DEVICE_INVALID) { + DisconnectDevice(&g_devs[MU_OFFSET + (XBOX_CTRL_NUM_SLOTS * port_num) + slot], port, ack); } // update bindings slot else { @@ -270,9 +264,9 @@ void InputDeviceManager::UpdateDevices(std::string_view port, bool ack) } // update bindings else { - auto dev1 = g_InputDeviceManager.FindDevice(port); - if (dev1 != nullptr) { - dev1->SetPort(port, false); + auto host_dev = g_InputDeviceManager.FindDevice(port); + if (host_dev != nullptr) { + host_dev->SetPort(port, false); } if (type != to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)) { if (type != to_underlying(dev->type)) { @@ -307,9 +301,9 @@ void InputDeviceManager::DisconnectDevice(DeviceState *dev, std::string_view por else { dev->bPendingRemoval = true; } - auto dev1 = g_InputDeviceManager.FindDevice(port); - if (dev1 != nullptr) { - dev1->SetPort(port, false); + auto host_dev = g_InputDeviceManager.FindDevice(port); + if (host_dev != nullptr) { + host_dev->SetPort(port, false); } } @@ -322,15 +316,15 @@ void InputDeviceManager::BindHostDevice(int type, std::string_view port) char dev_name[50]; char dev_control_names[HIGHEST_NUM_BUTTONS][HOST_BUTTON_NAME_LENGTH]; - int port1, slot; - PortStr2Int(port, &port1, &slot); - g_EmuShared->GetInputDevNameSettings(dev_name, port1); - g_EmuShared->GetInputBindingsSettings(dev_control_names, dev_num_buttons[type], port1); + int port_num, slot; + PortStr2Int(port, &port_num, &slot); + g_EmuShared->GetInputDevNameSettings(dev_name, port_num); + g_EmuShared->GetInputBindingsSettings(dev_control_names, dev_num_buttons[type], port_num); auto dev = FindDevice(std::string(dev_name)); if (dev != nullptr) { - std::string port1(port); - dev->ClearBindings(port1); + std::string port_str(port); + dev->ClearBindings(port_str); std::vector controls = dev->GetIoControls(); for (int index = 0; index < dev_num_buttons[type]; index++) { std::string dev_button(dev_control_names[index]); @@ -340,7 +334,7 @@ void InputDeviceManager::BindHostDevice(int type, std::string_view port) } return false; }); - dev->SetBindings(index, (it != controls.end()) ? *it : nullptr, port1); + dev->SetBindings(index, (it != controls.end()) ? *it : nullptr, port_str); } dev->SetPort(port, true); } @@ -357,19 +351,19 @@ bool InputDeviceManager::UpdateXboxPortInput(int port, void* buffer, int directi // If somebody else is currently holding the lock, we won't wait and instead report no input changes if (!g_renderbase->IsImGuiFocus() && m_Mtx.try_lock()) { for (auto &dev : m_Devices) { - std::string port1 = std::to_string(port); - if (dev->GetPort(port1)) { + std::string port_str = std::to_string(port); + if (dev->GetPort(port_str)) { switch (type) { case to_underlying(XBOX_INPUT_DEVICE::MS_CONTROLLER_DUKE): case to_underlying(XBOX_INPUT_DEVICE::MS_CONTROLLER_S): case to_underlying(XBOX_INPUT_DEVICE::ARCADE_STICK): - has_changed = UpdateInputXpad(dev, buffer, direction, port1); + has_changed = UpdateInputXpad(dev, buffer, direction, port_str); m_Mtx.unlock(); return has_changed; case to_underlying(XBOX_INPUT_DEVICE::STEEL_BATTALION_CONTROLLER): - has_changed = UpdateInputSBC(dev, buffer, direction, port, port1); + has_changed = UpdateInputSBC(dev, buffer, direction, port, port_str); m_Mtx.unlock(); return has_changed; @@ -381,7 +375,7 @@ bool InputDeviceManager::UpdateXboxPortInput(int port, void* buffer, int directi case to_underlying(XBOX_INPUT_DEVICE::STEERING_WHEEL): case to_underlying(XBOX_INPUT_DEVICE::IR_DONGLE): EmuLog(LOG_LEVEL::ERROR2, "An unsupported device is attached at port %d! The device was %s", - Gui2XboxPortArray[port], GetInputDeviceName(type).c_str()); + PortUserFormat(port_str).c_str(), GetInputDeviceName(type).c_str()); break; } @@ -393,9 +387,9 @@ bool InputDeviceManager::UpdateXboxPortInput(int port, void* buffer, int directi return has_changed; } -bool InputDeviceManager::UpdateInputXpad(std::shared_ptr& Device, void* Buffer, int Direction, const std::string &Port1) +bool InputDeviceManager::UpdateInputXpad(std::shared_ptr& Device, void* Buffer, int Direction, const std::string &Port) { - std::map bindings = Device->GetBindings(Port1); + std::map bindings = Device->GetBindings(Port); assert(bindings.size() == static_cast(dev_num_buttons[to_underlying(XBOX_INPUT_DEVICE::MS_CONTROLLER_DUKE)])); if (Direction == DIRECTION_IN) { @@ -457,9 +451,9 @@ bool InputDeviceManager::UpdateInputXpad(std::shared_ptr& Device, v return true; } -bool InputDeviceManager::UpdateInputSBC(std::shared_ptr& Device, void* Buffer, int Direction, int Port, const std::string &Port1) +bool InputDeviceManager::UpdateInputSBC(std::shared_ptr& Device, void* Buffer, int Direction, int Port_num, const std::string &Port) { - std::map bindings = Device->GetBindings(Port1); + std::map bindings = Device->GetBindings(Port); assert(bindings.size() == static_cast(dev_num_buttons[to_underlying(XBOX_INPUT_DEVICE::STEEL_BATTALION_CONTROLLER)])); // NOTE: the output state is not supported @@ -480,7 +474,7 @@ bool InputDeviceManager::UpdateInputSBC(std::shared_ptr& Device, vo // 8 -> TunerDial Down // 9 -> GearLever Up // 10 -> GearLever Down - static uint16_t last_in_state[4] = { 0, 0, 0, 0 }; + static uint16_t last_in_state[XBOX_NUM_PORTS] = { 0, 0, 0, 0 }; SBCInput *in_buf = static_cast(Buffer); for (int i = 0; i < 4; i++) { ControlState state = (bindings[i] != nullptr) ? dynamic_cast(bindings[i])->GetState() : 0.0; @@ -496,10 +490,10 @@ bool InputDeviceManager::UpdateInputSBC(std::shared_ptr& Device, vo for (int i = 4, j = 0; i < 6; i++, j++) { ControlState state = (bindings[i] != nullptr) ? dynamic_cast(bindings[i])->GetState() : 0.0; uint16_t curr_in_state = static_cast(!!state); - if ((~curr_in_state) & ((last_in_state[Port] >> j) & 1)) { + if ((~curr_in_state) & ((last_in_state[Port_num] >> j) & 1)) { in_buf->wButtons[0] ^= (1 << i); } - (last_in_state[Port] &= ~(1 << j)) |= (curr_in_state << j); + (last_in_state[Port_num] &= ~(1 << j)) |= (curr_in_state << j); } for (int i = 6; i < 34; i++) { @@ -516,10 +510,10 @@ bool InputDeviceManager::UpdateInputSBC(std::shared_ptr& Device, vo for (int i = 34, j = 2; i < 39; i++, j++) { ControlState state = (bindings[i] != nullptr) ? dynamic_cast(bindings[i])->GetState() : 0.0; uint16_t curr_in_state = static_cast(!!state); - if ((~curr_in_state) & ((last_in_state[Port] >> j) & 1)) { + if ((~curr_in_state) & ((last_in_state[Port_num] >> j) & 1)) { in_buf->wButtons[2] ^= (1 << (i % 16)); } - (last_in_state[Port] &= ~(1 << j)) |= (curr_in_state << j); + (last_in_state[Port_num] &= ~(1 << j)) |= (curr_in_state << j); } for (int i = 39; i < 49; i += 2) { @@ -578,7 +572,7 @@ bool InputDeviceManager::UpdateInputSBC(std::shared_ptr& Device, vo for (int i = 52, j = 7; i < 56; i++, j++) { ControlState state = (bindings[i] != nullptr) ? dynamic_cast(bindings[i])->GetState() : 0.0; uint16_t curr_in_state = static_cast(!!state); - if ((~curr_in_state) & ((last_in_state[Port] >> j) & 1)) { + if ((~curr_in_state) & ((last_in_state[Port_num] >> j) & 1)) { switch (i) { case 52: @@ -606,7 +600,7 @@ bool InputDeviceManager::UpdateInputSBC(std::shared_ptr& Device, vo break; } } - (last_in_state[Port] &= ~(1 << j)) |= (curr_in_state << j); + (last_in_state[Port_num] &= ~(1 << j)) |= (curr_in_state << j); } } @@ -616,7 +610,7 @@ bool InputDeviceManager::UpdateInputSBC(std::shared_ptr& Device, vo void InputDeviceManager::RefreshDevices() { std::unique_lock lck(m_Mtx); - Sdl::SdlPopulateOK = false; + Sdl::PopulateOK = false; m_Devices.clear(); lck.unlock(); XInput::PopulateDevices(); @@ -624,7 +618,7 @@ void InputDeviceManager::RefreshDevices() Sdl::PopulateDevices(); lck.lock(); m_Cv.wait(lck, []() { - return Sdl::SdlPopulateOK; + return Sdl::PopulateOK; }); for (auto &dev : m_Devices) { if (StrStartsWith(dev->GetDeviceName(), "KeyboardMouse")) { diff --git a/src/common/input/InputManager.h b/src/common/input/InputManager.h index 56605a806..e47f2cfdf 100644 --- a/src/common/input/InputManager.h +++ b/src/common/input/InputManager.h @@ -37,11 +37,20 @@ #undef SetPort #endif -#define SLOT_TOP 0 -#define SLOT_BOTTOM 1 +#define PORT_INVALID -1 +#define PORT_1 0 +#define PORT_2 1 +#define PORT_3 2 +#define PORT_4 3 +#define XBOX_NUM_PORTS 4 + +#define SLOT_TOP 0 +#define SLOT_BOTTOM 1 +#define XBOX_CTRL_NUM_SLOTS 2 #define CTRL_OFFSET 0 #define MU_OFFSET 4 +#define MAX_DEVS (XBOX_NUM_PORTS + XBOX_CTRL_NUM_SLOTS * XBOX_NUM_PORTS) extern int dev_num_buttons[to_underlying(XBOX_INPUT_DEVICE::DEVICE_MAX)]; @@ -56,6 +65,8 @@ inline XBOX_INPUT_DEVICE input_support_list[] = { inline XBOX_INPUT_DEVICE slot_support_list[] = { XBOX_INPUT_DEVICE::DEVICE_INVALID, XBOX_INPUT_DEVICE::MEMORY_UNIT, + // Microphone + // Phantasy star online keyboard }; #pragma pack(1) @@ -109,7 +120,7 @@ union InputBuff { }; struct DeviceInfo { - xbox::HANDLE hhandle; // device handle returned by xapi + xbox::HANDLE hHandle; // device handle returned by xapi bool bAutoPoll; // autopoll on/off, as instructed by the title in XInputOpen bool bAutoPollDefault; // default autopoll value, depending on device type uint8_t ucType; // xapi type @@ -121,7 +132,6 @@ struct DeviceInfo { }; struct DeviceState { - DeviceState *upstream; std::string port; int port_idx; XBOX_INPUT_DEVICE type; @@ -129,9 +139,10 @@ struct DeviceState { bool bSignaled; DeviceInfo info; DeviceState *slots[XBOX_CTRL_NUM_SLOTS]; + DeviceState *upstream; }; -extern DeviceState g_devs[4 + 8]; +extern DeviceState g_devs[MAX_DEVS]; class InputDeviceManager @@ -165,9 +176,9 @@ public: private: // update input for an xbox controller - bool UpdateInputXpad(std::shared_ptr& Device, void* Buffer, int Direction, const std::string &Port1); + bool UpdateInputXpad(std::shared_ptr& Device, void* Buffer, int Direction, const std::string &Port); // update input for a Steel Battalion controller - bool UpdateInputSBC(std::shared_ptr& Device, void* Buffer, int Direction, int Port, const std::string &Port1); + bool UpdateInputSBC(std::shared_ptr& Device, void* Buffer, int Direction, int Port_num, const std::string &Port); // bind a host device to an emulated device void BindHostDevice(int type, std::string_view port); // connect a device to the emulated machine diff --git a/src/common/input/InputWindow.h b/src/common/input/InputWindow.h index 0534dd349..4df21cae4 100644 --- a/src/common/input/InputWindow.h +++ b/src/common/input/InputWindow.h @@ -121,7 +121,7 @@ private: // handle of the rumble combobox HWND m_hwnd_rumble_list; // handles of the slot combobox - HWND m_hwnd_slot_list[2]; + HWND m_hwnd_slot_list[XBOX_CTRL_NUM_SLOTS]; // currently selected rumble control std::string m_rumble; }; diff --git a/src/common/input/RawDevice.cpp b/src/common/input/RawDevice.cpp index a4c6c4343..fdceecc7b 100644 --- a/src/common/input/RawDevice.cpp +++ b/src/common/input/RawDevice.cpp @@ -35,7 +35,7 @@ namespace RawInput { - int RawInputInitStatus = RAWINPUT_NOT_INIT; + int InitStatus = NOT_INIT; bool IgnoreHotplug = true; void Init(std::mutex &Mtx, bool is_gui, HWND hwnd) @@ -44,7 +44,7 @@ namespace RawInput if (is_gui) { // We don't need to monitor xinput device changes from the gui, because there we have the refresh button to detect changes - RawInputInitStatus = RAWINPUT_INIT_SUCCESS; + InitStatus = INIT_SUCCESS; return; } @@ -69,16 +69,16 @@ namespace RawInput static_cast(sizeof(decltype(devices)::value_type)))) { EmuLog(LOG_LEVEL::ERROR2, "RegisterRawInputDevices failed: %i", GetLastError()); - RawInputInitStatus = RAWINPUT_INIT_ERROR; + InitStatus = INIT_ERROR; return; } - RawInputInitStatus = RAWINPUT_INIT_SUCCESS; + InitStatus = INIT_SUCCESS; } void DeInit() { - RawInputInitStatus = RAWINPUT_NOT_INIT; + InitStatus = NOT_INIT; IgnoreHotplug = true; } } diff --git a/src/common/input/RawDevice.h b/src/common/input/RawDevice.h index 7be2bc3f5..6d81a44a9 100644 --- a/src/common/input/RawDevice.h +++ b/src/common/input/RawDevice.h @@ -33,15 +33,15 @@ namespace RawInput { - typedef enum _RAWINPUT_INIT_STATUS : int + typedef enum _INIT_STATUS : int { - RAWINPUT_NOT_INIT = -2, - RAWINPUT_INIT_ERROR, - RAWINPUT_INIT_SUCCESS, + NOT_INIT = -2, + INIT_ERROR, + INIT_SUCCESS, } - RAWINPUT_INIT_STATUS; + INIT_STATUS; - extern int RawInputInitStatus; + extern int InitStatus; extern bool IgnoreHotplug; // initialize RawInput diff --git a/src/common/input/SdlJoystick.cpp b/src/common/input/SdlJoystick.cpp index e571ee3a7..6a50d662b 100644 --- a/src/common/input/SdlJoystick.cpp +++ b/src/common/input/SdlJoystick.cpp @@ -54,8 +54,8 @@ namespace Sdl uint32_t PopulateEvent_t; uint32_t UpdateInputEvent_t; uint32_t DeviceRemoveAck_t; - int SdlInitStatus = SDL_NOT_INIT; - bool SdlPopulateOK = false; + int InitStatus = NOT_INIT; + bool PopulateOK = false; void Init(std::mutex& Mtx, std::condition_variable& Cv, bool is_gui) { @@ -65,7 +65,7 @@ namespace Sdl if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) < 0) { EmuLog(LOG_LEVEL::ERROR2, "Failed to initialize SDL subsystem! The error was: %s", SDL_GetError()); - SdlInitStatus = SDL_INIT_ERROR; + InitStatus = INIT_ERROR; lck.unlock(); Cv.notify_one(); return; @@ -74,7 +74,7 @@ namespace Sdl if (CustomEvent_t == (uint32_t)-1) { SDL_Quit(); EmuLog(LOG_LEVEL::ERROR2, "Failed to create SDL custom events!"); - SdlInitStatus = SDL_INIT_ERROR; + InitStatus = INIT_ERROR; lck.unlock(); Cv.notify_one(); return; @@ -96,7 +96,7 @@ namespace Sdl break; } } - SdlInitStatus = SDL_INIT_SUCCESS; + InitStatus = INIT_SUCCESS; lck.unlock(); Cv.notify_one(); @@ -133,10 +133,6 @@ namespace Sdl case SDL_JOYBUTTONUP: id = Event.jbutton.which; break; - - default: { - // unreachable - } } auto dev = g_InputDeviceManager.FindDevice(id); if (dev != nullptr) { @@ -147,7 +143,7 @@ namespace Sdl for (int i = 0; i < SDL_NumJoysticks(); i++) { OpenSdlDevice(i); } - SdlPopulateOK = true; + PopulateOK = true; Cv.notify_one(); } else if (Event.type == ExitEvent_t) { @@ -161,8 +157,8 @@ namespace Sdl XInput::GetDeviceChanges(); DInput::GetDeviceChanges(); std::string port = std::to_string(*static_cast(Event.user.data1)); - int port1, slot; - PortStr2Int(port, &port1, &slot); + int port_num, slot; + PortStr2Int(port, &port_num, &slot); g_InputDeviceManager.UpdateDevices(port, false); // Force an update of the entire slot connectivity of this port @@ -185,7 +181,7 @@ namespace Sdl void DeInit(std::thread& Thr) { - SdlInitStatus = SDL_NOT_INIT; + InitStatus = NOT_INIT; if (!Thr.joinable()) { return; } diff --git a/src/common/input/SdlJoystick.h b/src/common/input/SdlJoystick.h index b6d18008e..688d84a07 100644 --- a/src/common/input/SdlJoystick.h +++ b/src/common/input/SdlJoystick.h @@ -35,20 +35,20 @@ namespace Sdl { - typedef enum _SDL_INIT_STATUS : int + typedef enum _INIT_STATUS : int { - SDL_NOT_INIT = -2, - SDL_INIT_ERROR, - SDL_INIT_SUCCESS, + NOT_INIT = -2, + INIT_ERROR, + INIT_SUCCESS, } - SDL_INIT_STATUS; + INIT_STATUS; extern uint32_t ExitEvent_t; extern uint32_t PopulateEvent_t; extern uint32_t UpdateInputEvent_t; extern uint32_t DeviceRemoveAck_t; - extern int SdlInitStatus; - extern bool SdlPopulateOK; + extern int InitStatus; + extern bool PopulateOK; // initialize SDL void Init(std::mutex& Mtx, std::condition_variable& Cv, bool is_gui); diff --git a/src/common/input/XInputPad.cpp b/src/common/input/XInputPad.cpp index 1ac1a9597..53016d672 100644 --- a/src/common/input/XInputPad.cpp +++ b/src/common/input/XInputPad.cpp @@ -70,7 +70,7 @@ namespace XInput static XInputGetState_t PXInputGetState = nullptr; static bool haveGuideButton = false; - int XInputInitStatus = XINPUT_NOT_INIT; + int InitStatus = NOT_INIT; uint8_t DevicesConnected = 0; static const struct @@ -118,7 +118,7 @@ namespace XInput hXInput = ::LoadLibrary(TEXT(xinput_dll_name.c_str())); if (!hXInput) { EmuLog(LOG_LEVEL::ERROR2, "Failed to initialize XInput subsystem!"); - XInputInitStatus = XINPUT_INIT_ERROR; + InitStatus = INIT_ERROR; return; } } @@ -147,15 +147,15 @@ namespace XInput ::FreeLibrary(hXInput); hXInput = nullptr; EmuLog(LOG_LEVEL::ERROR2, "Failed to find XInput functions!"); - XInputInitStatus = XINPUT_INIT_ERROR; + InitStatus = INIT_ERROR; return; } - XInputInitStatus = XINPUT_INIT_SUCCESS; + InitStatus = INIT_SUCCESS; } void DeInit() { - XInputInitStatus = XINPUT_NOT_INIT; + InitStatus = NOT_INIT; if (hXInput) { ::FreeLibrary(hXInput); diff --git a/src/common/input/XInputPad.h b/src/common/input/XInputPad.h index f6faae243..c64822805 100644 --- a/src/common/input/XInputPad.h +++ b/src/common/input/XInputPad.h @@ -34,15 +34,15 @@ namespace XInput { - typedef enum _XINPUT_INIT_STATUS : int + typedef enum _INIT_STATUS : int { - XINPUT_NOT_INIT = -2, - XINPUT_INIT_ERROR, - XINPUT_INIT_SUCCESS, + NOT_INIT = -2, + INIT_ERROR, + INIT_SUCCESS, } - XINPUT_INIT_STATUS; + INIT_STATUS; - extern int XInputInitStatus; + extern int InitStatus; extern uint8_t DevicesConnected; // initialize XInput diff --git a/src/common/win32/EmuShared.h b/src/common/win32/EmuShared.h index aff5a810e..1f685437c 100644 --- a/src/common/win32/EmuShared.h +++ b/src/common/win32/EmuShared.h @@ -367,10 +367,10 @@ class EmuShared : public Mutex bool m_bFirstLaunch; bool m_bClipCursor; unsigned int m_dwKrnlProcID; // Only used for kernel mode level. - int m_DeviceType[4]; - int m_SlotDeviceType[4][XBOX_CTRL_NUM_SLOTS]; - char m_DeviceControlNames[4][HIGHEST_NUM_BUTTONS][HOST_BUTTON_NAME_LENGTH]; - char m_DeviceName[4][50]; + int m_DeviceType[XBOX_NUM_PORTS]; + int m_SlotDeviceType[XBOX_NUM_PORTS][XBOX_CTRL_NUM_SLOTS]; + char m_DeviceControlNames[XBOX_NUM_PORTS][HIGHEST_NUM_BUTTONS][HOST_BUTTON_NAME_LENGTH]; + char m_DeviceName[XBOX_NUM_PORTS][50]; char m_TitleMountPath[xbox::max_path]; // Settings class in memory should not be tampered by third-party. diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.h b/src/core/hle/D3D8/Direct3D9/Direct3D9.h index 9d5a68fe5..f3ae9c596 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.h +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.h @@ -37,8 +37,7 @@ #define DIRECTDRAW_VERSION 0x0700 #include -extern void LookupTrampolinesD3D(); -extern void LookupTrampolinesXAPI(); +void LookupTrampolinesD3D(); // initialize render window extern void CxbxInitWindow(bool bFullInit); diff --git a/src/core/hle/XAPI/Xapi.cpp b/src/core/hle/XAPI/Xapi.cpp index 952cddb39..0cdef1d9a 100644 --- a/src/core/hle/XAPI/Xapi.cpp +++ b/src/core/hle/XAPI/Xapi.cpp @@ -59,7 +59,7 @@ std::atomic g_bXppGuard = false; // Allocate enough memory for the max number of devices we can support simultaneously // 4 duke / S / sbc / arcade joystick (mutually exclusive) + 8 memory units -DeviceState g_devs[4 + 8]; +DeviceState g_devs[MAX_DEVS]; xbox::ulong_xt g_Mounted_MUs = 0; xbox::char_xt g_AltLett_MU = 0; @@ -173,9 +173,9 @@ void UpdateXppState(DeviceState *dev, XBOX_INPUT_DEVICE type, std::string_view p return; } - int port1, slot; - PortStr2Int(port, &port1, &slot); - xbox::ulong_xt port_mask = 1 << port1; + int port_num, slot; + PortStr2Int(port, &port_num, &slot); + xbox::ulong_xt port_mask = 1 << port_num; xbox::ulong_xt slot_mask = 0; // Guard against the unfortunate case where XGetDevices or XGetDeviceChanges have already checked for g_bIsDevicesInitializing @@ -209,11 +209,11 @@ void ConstructHleInputDevice(DeviceState *dev, DeviceState *upstream, int type, return; } // Set up common device state - int port1, slot; - PortStr2Int(port, &port1, &slot); + int port_num, slot; + PortStr2Int(port, &port_num, &slot); dev->upstream = nullptr; dev->port = port; - dev->port_idx = port1; + dev->port_idx = port_num; dev->bPendingRemoval = false; dev->bSignaled = false; dev->info.dwPacketNumber = 0; @@ -330,8 +330,8 @@ void DestructHleInputDevice(DeviceState *dev) case XBOX_INPUT_DEVICE::MEMORY_UNIT: { assert(dev->upstream != nullptr); - int port1, slot; - PortStr2Int(port, &port1, &slot); + int port_num, slot; + PortStr2Int(port, &port_num, &slot); assert(slot != PORT_INVALID); dev->upstream->slots[slot] = nullptr; } @@ -446,7 +446,7 @@ xbox::dword_xt CxbxImpl_XInputHandler(xbox::HANDLE hDevice, xbox::PXINPUT_STATE DeviceState *dev = static_cast(hDevice); int port = dev->port_idx; - if ((g_devs[port].info.hhandle == hDevice) && !g_devs[port].bPendingRemoval) { + if ((g_devs[port].info.hHandle == hDevice) && !g_devs[port].bPendingRemoval) { if (g_devs[port].info.bAutoPoll != IsXInputPoll) { if (g_InputDeviceManager.UpdateXboxPortInput(port, &g_devs[port].info.buff, DIRECTION_IN, to_underlying(g_devs[port].type))) { g_devs[port].info.dwPacketNumber++; @@ -639,8 +639,8 @@ xbox::HANDLE WINAPI xbox::EMUPATCH(XInputOpen) if (DeviceType == g_devs[dwPort].type) { g_devs[dwPort].info.bAutoPoll = pPollingParameters != xbox::zeroptr ? pPollingParameters->fAutoPoll : g_devs[dwPort].info.bAutoPollDefault; - g_devs[dwPort].info.hhandle = &g_devs[dwPort]; - RETURN(g_devs[dwPort].info.hhandle); + g_devs[dwPort].info.hHandle = &g_devs[dwPort]; + RETURN(g_devs[dwPort].info.hHandle); } } @@ -658,8 +658,8 @@ xbox::void_xt WINAPI xbox::EMUPATCH(XInputClose) LOG_FUNC_ONE_ARG(hDevice); DeviceState *dev = static_cast(hDevice); - if (g_devs[dev->port_idx].info.hhandle == hDevice) { - dev->info.hhandle = NULL; + if (g_devs[dev->port_idx].info.hHandle == hDevice) { + dev->info.hHandle = NULL; } } @@ -696,7 +696,7 @@ xbox::dword_xt WINAPI xbox::EMUPATCH(XInputGetCapabilities) dword_xt ret = ERROR_DEVICE_NOT_CONNECTED; DeviceState *dev = static_cast(hDevice); int port = dev->port_idx; - if (g_devs[port].info.hhandle == hDevice && !g_devs[port].bPendingRemoval) { + if (g_devs[port].info.hHandle == hDevice && !g_devs[port].bPendingRemoval) { pCapabilities->SubType = g_devs[port].info.ucSubType; UCHAR* pCap = (UCHAR*)(&pCapabilities->In); std::memset(pCap, 0xFF, g_devs[port].info.ucInputStateSize + g_devs[port].info.ucFeedbackSize); @@ -745,7 +745,7 @@ xbox::dword_xt WINAPI xbox::EMUPATCH(XInputSetState) DeviceState *dev = static_cast(hDevice); int port = dev->port_idx; - if (g_devs[port].info.hhandle == hDevice && !g_devs[port].bPendingRemoval) { + if (g_devs[port].info.hHandle == hDevice && !g_devs[port].bPendingRemoval) { pFeedback->Header.dwStatus = ERROR_IO_PENDING; g_InputDeviceManager.UpdateXboxPortInput(port, (void*)&pFeedback->Rumble, DIRECTION_OUT, to_underlying(g_devs[port].type)); pFeedback->Header.dwStatus = ERROR_SUCCESS; diff --git a/src/core/hle/XAPI/Xapi.h b/src/core/hle/XAPI/Xapi.h index b70125f64..1b5d2949f 100644 --- a/src/core/hle/XAPI/Xapi.h +++ b/src/core/hle/XAPI/Xapi.h @@ -25,6 +25,8 @@ #ifndef XAPI_H #define XAPI_H +void LookupTrampolinesXAPI(); + #include "xbox_types.h" namespace xbox { diff --git a/src/core/kernel/exports/EmuKrnlNt.cpp b/src/core/kernel/exports/EmuKrnlNt.cpp index 7f672a7f1..a5c1a2db9 100644 --- a/src/core/kernel/exports/EmuKrnlNt.cpp +++ b/src/core/kernel/exports/EmuKrnlNt.cpp @@ -835,6 +835,7 @@ XBSYSAPI EXPORTNUM(200) xbox::ntstatus_xt NTAPI xbox::NtFsControlFile switch (FsControlCode) { case fsctl_dismount_volume: { + // HACK: this should just free the resources assocoated with the volume, it should not reformat it int partitionNumber = CxbxGetPartitionNumberFromHandle(FileHandle); if (partitionNumber > 0) { CxbxFormatPartitionByHandle(FileHandle); diff --git a/src/core/kernel/init/CxbxKrnl.cpp b/src/core/kernel/init/CxbxKrnl.cpp index edd786d6a..ef960cf52 100644 --- a/src/core/kernel/init/CxbxKrnl.cpp +++ b/src/core/kernel/init/CxbxKrnl.cpp @@ -1945,14 +1945,14 @@ void CxbxKrnlShutDown(bool is_reboot) // Shutdown the input device manager g_InputDeviceManager.Shutdown(); - // Shutdown the memory manager - g_VMManager.Shutdown(); - if (g_io_mu_metadata) { delete g_io_mu_metadata; g_io_mu_metadata = nullptr; } + // Shutdown the memory manager + g_VMManager.Shutdown(); + // Shutdown the render manager if (g_renderbase != nullptr) { g_renderbase->Shutdown(); diff --git a/src/core/kernel/support/EmuFile.cpp b/src/core/kernel/support/EmuFile.cpp index c96f2dae1..b7afe8429 100644 --- a/src/core/kernel/support/EmuFile.cpp +++ b/src/core/kernel/support/EmuFile.cpp @@ -171,8 +171,9 @@ DeviceType CxbxrGetDeviceTypeFromHandle(HANDLE hFile) return DeviceType::MU; } - EmuNtSymbolicLinkObject *ret = FindNtSymbolicLinkObjectByDevice(DeviceCdrom0); - if (ret != nullptr && path.rfind(ret->wHostSymbolicLinkPath) != std::string::npos) { + EmuDirPath hybrid_path; + FindEmuDirPathByDevice(DeviceCdrom0, hybrid_path); + if (hybrid_path.HostDirPath != "") { return DeviceType::Cdrom0; } @@ -929,10 +930,6 @@ NTSTATUS EmuNtSymbolicLinkObject::Init(std::string aSymbolicLinkName, std::strin } else { - std::mbstate_t ps = std::mbstate_t(); - const char *src = HostSymbolicLinkPath.c_str(); - wHostSymbolicLinkPath.resize(HostSymbolicLinkPath.size()); - std::mbsrtowcs(wHostSymbolicLinkPath.data(), &src, wHostSymbolicLinkPath.size(), &ps); NtSymbolicLinkObjects[DriveLetter - 'A'] = this; EmuLog(LOG_LEVEL::DEBUG, "Linked \"%s\" to \"%s\" (residing at \"%s\")", aSymbolicLinkName.c_str(), aFullPath.c_str(), HostSymbolicLinkPath.c_str()); } @@ -1018,19 +1015,6 @@ EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByRootHandle(const HANDLE Handl } -EmuNtSymbolicLinkObject *FindNtSymbolicLinkObjectByDevice(const std::string_view Device) -{ - for (char DriveLetter = 'A'; DriveLetter <= 'Z'; DriveLetter++) - { - EmuNtSymbolicLinkObject *result = NtSymbolicLinkObjects[DriveLetter - 'A']; - if ((result != nullptr) && (result->XboxSymbolicLinkPath == Device)) - return result; - } - - return nullptr; -} - - void _CxbxPVOIDDeleter(PVOID *ptr) { if (*ptr) { diff --git a/src/core/kernel/support/EmuFile.h b/src/core/kernel/support/EmuFile.h index fe0dabc52..eedc2e2b2 100644 --- a/src/core/kernel/support/EmuFile.h +++ b/src/core/kernel/support/EmuFile.h @@ -231,7 +231,6 @@ public: bool IsHostBasedPath; std::string XboxSymbolicLinkPath; std::string HostSymbolicLinkPath; - std::wstring wHostSymbolicLinkPath; HANDLE RootDirectoryHandle; NTSTATUS Init(std::string aSymbolicLinkName, std::string aFullPath); ~EmuNtSymbolicLinkObject(); @@ -284,7 +283,6 @@ EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByDriveLetter(const char DriveL EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByName(std::string SymbolicLinkName); void FindEmuDirPathByDevice(std::string DeviceName, EmuDirPath& hybrid_path); EmuNtSymbolicLinkObject* FindNtSymbolicLinkObjectByRootHandle(HANDLE Handle); -EmuNtSymbolicLinkObject *FindNtSymbolicLinkObjectByDevice(const std::string_view Device); DeviceType CxbxrGetDeviceTypeFromHandle(HANDLE hFile); void CleanupSymbolicLinks();