Review remarks + some code cleanup

This commit is contained in:
ergo720 2021-06-23 17:21:15 +02:00
parent efd9108279
commit e6650da541
22 changed files with 146 additions and 171 deletions

View File

@ -33,7 +33,6 @@
#include "core\kernel\support\Emu.h"
#include "EmuShared.h"
#include <filesystem>
#include "common\input\InputManager.h"
#include "common\input\layout_xbox_device.h"
#include <fstream>
#include "common/util/cliConfig.hpp"

View File

@ -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 <string>
#include <array>
@ -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;
};

View File

@ -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

View File

@ -33,6 +33,7 @@
// https://github.com/dolphin-emu/dolphin
#include "InputDevice.h"
#include "InputManager.h"
#include "common\util\CxbxUtil.h"
#include <algorithm>
#include <charconv>
@ -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::IoControl*> 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;

View File

@ -36,12 +36,6 @@
#include <condition_variable>
#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

View File

@ -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<bool(const InputDevice*)> 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<InputDevice::IoControl *> 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<InputDevice>& Device, void* Buffer, int Direction, const std::string &Port1)
bool InputDeviceManager::UpdateInputXpad(std::shared_ptr<InputDevice>& Device, void* Buffer, int Direction, const std::string &Port)
{
std::map<int, InputDevice::IoControl*> bindings = Device->GetBindings(Port1);
std::map<int, InputDevice::IoControl*> bindings = Device->GetBindings(Port);
assert(bindings.size() == static_cast<size_t>(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<InputDevice>& Device, v
return true;
}
bool InputDeviceManager::UpdateInputSBC(std::shared_ptr<InputDevice>& Device, void* Buffer, int Direction, int Port, const std::string &Port1)
bool InputDeviceManager::UpdateInputSBC(std::shared_ptr<InputDevice>& Device, void* Buffer, int Direction, int Port_num, const std::string &Port)
{
std::map<int, InputDevice::IoControl*> bindings = Device->GetBindings(Port1);
std::map<int, InputDevice::IoControl*> bindings = Device->GetBindings(Port);
assert(bindings.size() == static_cast<size_t>(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<InputDevice>& 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<SBCInput *>(Buffer);
for (int i = 0; i < 4; i++) {
ControlState state = (bindings[i] != nullptr) ? dynamic_cast<InputDevice::Input *>(bindings[i])->GetState() : 0.0;
@ -496,10 +490,10 @@ bool InputDeviceManager::UpdateInputSBC(std::shared_ptr<InputDevice>& Device, vo
for (int i = 4, j = 0; i < 6; i++, j++) {
ControlState state = (bindings[i] != nullptr) ? dynamic_cast<InputDevice::Input *>(bindings[i])->GetState() : 0.0;
uint16_t curr_in_state = static_cast<uint16_t>(!!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<InputDevice>& Device, vo
for (int i = 34, j = 2; i < 39; i++, j++) {
ControlState state = (bindings[i] != nullptr) ? dynamic_cast<InputDevice::Input *>(bindings[i])->GetState() : 0.0;
uint16_t curr_in_state = static_cast<uint16_t>(!!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<InputDevice>& Device, vo
for (int i = 52, j = 7; i < 56; i++, j++) {
ControlState state = (bindings[i] != nullptr) ? dynamic_cast<InputDevice::Input *>(bindings[i])->GetState() : 0.0;
uint16_t curr_in_state = static_cast<uint16_t>(!!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<InputDevice>& 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<InputDevice>& Device, vo
void InputDeviceManager::RefreshDevices()
{
std::unique_lock<std::mutex> 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")) {

View File

@ -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<InputDevice>& Device, void* Buffer, int Direction, const std::string &Port1);
bool UpdateInputXpad(std::shared_ptr<InputDevice>& Device, void* Buffer, int Direction, const std::string &Port);
// update input for a Steel Battalion controller
bool UpdateInputSBC(std::shared_ptr<InputDevice>& Device, void* Buffer, int Direction, int Port, const std::string &Port1);
bool UpdateInputSBC(std::shared_ptr<InputDevice>& 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

View File

@ -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;
};

View File

@ -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<UINT>(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;
}
}

View File

@ -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

View File

@ -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<int *>(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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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.

View File

@ -37,8 +37,7 @@
#define DIRECTDRAW_VERSION 0x0700
#include <ddraw.h>
extern void LookupTrampolinesD3D();
extern void LookupTrampolinesXAPI();
void LookupTrampolinesD3D();
// initialize render window
extern void CxbxInitWindow(bool bFullInit);

View File

@ -59,7 +59,7 @@ std::atomic<bool> 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<DeviceState *>(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<DeviceState *>(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<DeviceState *>(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<DeviceState *>(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;

View File

@ -25,6 +25,8 @@
#ifndef XAPI_H
#define XAPI_H
void LookupTrampolinesXAPI();
#include "xbox_types.h"
namespace xbox {

View File

@ -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);

View File

@ -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();

View File

@ -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) {

View File

@ -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();