Skip to content

Commit

Permalink
Updated kernel file nt functions to support MUs + fixed bugs in xapi …
Browse files Browse the repository at this point in the history
…functions and input gui related to MUs
  • Loading branch information
ergo720 committed Jun 22, 2021
1 parent 5d5d09f commit de9913f
Show file tree
Hide file tree
Showing 19 changed files with 550 additions and 231 deletions.
19 changes: 12 additions & 7 deletions src/common/input/InputDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,27 +144,32 @@ class InputDevice

public:
// retrieves the map of input bindings
const std::map<int, IoControl*> GetBindings() const {
const std::map<int, IoControl*> GetBindings(const std::string &Port) const {
std::lock_guard<std::mutex> lck(m_BindingsMtx);
return m_Bindings;
return m_Bindings.find(Port)->second;
}
// sets a pair in the map of the input bindings
void SetBindings(int XButton, IoControl* Control) {
void SetBindings(int XButton, IoControl* Control, const std::string &Port) {
std::lock_guard<std::mutex> lck(m_BindingsMtx);
m_Bindings[XButton] = Control;
m_Bindings[Port][XButton] = Control;
}
// clears all input bindings for the specified xbox port
void ClearBindings(const std::string &Port) {
std::lock_guard<std::mutex> lck(m_BindingsMtx);
m_Bindings[Port].clear();
}

private:
// arbitrary ID assigned by to the device
// arbitrary ID assigned to the device
int m_ID;
// all the input controls detected and usable on this device
std::vector<Input*> m_Inputs;
// all the output controls detected and usable on this device
std::vector<Output*> m_Outputs;
// xbox port(s) this device is attached to
std::vector<std::string> m_XboxPort;
// button bindings to the xbox device buttons
std::map<int, IoControl*> m_Bindings;
// per xbox port button bindings to the xbox device buttons
std::unordered_map<std::string, std::map<int, IoControl*>> m_Bindings;
};

#endif
48 changes: 31 additions & 17 deletions src/common/input/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void InputDeviceManager::Initialize(bool is_gui, HWND hwnd)
g_EmuShared->GetInputSlotTypeSettings(&type, i, slot);
if (type != to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)) {
assert(type == to_underlying(XBOX_INPUT_DEVICE::MEMORY_UNIT));
ConstructHleInputDevice(&g_devs[MU_OFFSET + slot], &g_devs[CTRL_OFFSET + i], type, port + "." + std::to_string(slot));
ConstructHleInputDevice(&g_devs[MU_OFFSET + (XBOX_CTRL_NUM_SLOTS * i) + slot], &g_devs[CTRL_OFFSET + i], type, port + "." + std::to_string(slot));
}
}
}
Expand Down Expand Up @@ -225,7 +225,7 @@ void InputDeviceManager::RemoveDevice(std::function<bool(const InputDevice*)> Ca
void InputDeviceManager::UpdateDevices(std::string_view port, bool ack)
{
DeviceState *dev, *upstream;
int port1, type, slot;
int port1, slot, type;
PortStr2Int(port, &port1, &slot);
dev = &g_devs[port1];

Expand All @@ -234,16 +234,27 @@ void InputDeviceManager::UpdateDevices(std::string_view port, bool ack)
g_EmuShared->GetInputDevTypeSettings(&type, port1);
}
else { // Port references a device attached to a slot port
assert(dev->type == XBOX_INPUT_DEVICE::MS_CONTROLLER_DUKE ||
dev->type == XBOX_INPUT_DEVICE::MS_CONTROLLER_S);
upstream = dev;
dev = dev->slots[slot];
g_EmuShared->GetInputSlotTypeSettings(&type, port1, slot);
}

// connect slot
// updating a slot
if (dev == nullptr) {
ConnectDevice(&g_devs[MU_OFFSET + port1 + slot], upstream, type, port);
// 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);
}
// 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);
}
// update bindings slot
else {
// MUs don't have any host devices attached, so this is a nop for now
}
}
// connect
else if (type != to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID) &&
Expand All @@ -253,8 +264,8 @@ void InputDeviceManager::UpdateDevices(std::string_view port, bool ack)
// disconnect
else if (type == to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID) &&
dev->type != XBOX_INPUT_DEVICE::DEVICE_INVALID) {
// We don't need to check of we need to destroy child devices because the UpdateInputEvent_t message always
// calls us on the entire slot connectivity if the device has slots available
// We don't need to check if we need to destroy child devices because the UpdateInputEvent_t message always
// calls us on the entire slot connectivity of a port
DisconnectDevice(dev, port, ack);
}
// update bindings
Expand Down Expand Up @@ -309,7 +320,7 @@ void InputDeviceManager::DisconnectDevice(DeviceState *dev, std::string_view por
void InputDeviceManager::BindHostDevice(int type, std::string_view port)
{
if (type == to_underlying(XBOX_INPUT_DEVICE::MEMORY_UNIT)) {
// MUs don't have any host device bound, so we just return
// MUs don't have any host devices bound, so we just return
return;
}

Expand All @@ -322,6 +333,8 @@ void InputDeviceManager::BindHostDevice(int type, std::string_view port)

auto dev = FindDevice(std::string(dev_name));
if (dev != nullptr) {
std::string port1(port);
dev->ClearBindings(port1);
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]);
Expand All @@ -331,7 +344,7 @@ void InputDeviceManager::BindHostDevice(int type, std::string_view port)
}
return false;
});
dev->SetBindings(index, (it != controls.end()) ? *it : nullptr);
dev->SetBindings(index, (it != controls.end()) ? *it : nullptr, port1);
}
dev->SetPort(port, true);
}
Expand All @@ -348,18 +361,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) {
if (dev->GetPort(std::to_string(port))) {
std::string port1 = std::to_string(port);
if (dev->GetPort(port1)) {
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);
has_changed = UpdateInputXpad(dev, buffer, direction, port1);
m_Mtx.unlock();
return has_changed;

case to_underlying(XBOX_INPUT_DEVICE::STEEL_BATTALION_CONTROLLER):
has_changed = UpdateInputSBC(dev, buffer, direction, port);
has_changed = UpdateInputSBC(dev, buffer, direction, port, port1);
m_Mtx.unlock();
return has_changed;

Expand All @@ -383,9 +397,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)
bool InputDeviceManager::UpdateInputXpad(std::shared_ptr<InputDevice>& Device, void* Buffer, int Direction, const std::string &Port1)
{
std::map<int, InputDevice::IoControl*> bindings = Device->GetBindings();
std::map<int, InputDevice::IoControl*> bindings = Device->GetBindings(Port1);
assert(bindings.size() == static_cast<size_t>(dev_num_buttons[to_underlying(XBOX_INPUT_DEVICE::MS_CONTROLLER_DUKE)]));

if (Direction == DIRECTION_IN) {
Expand Down Expand Up @@ -447,9 +461,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)
bool InputDeviceManager::UpdateInputSBC(std::shared_ptr<InputDevice>& Device, void* Buffer, int Direction, int Port, const std::string &Port1)
{
std::map<int, InputDevice::IoControl*> bindings = Device->GetBindings();
std::map<int, InputDevice::IoControl*> bindings = Device->GetBindings(Port1);
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
Expand Down
4 changes: 2 additions & 2 deletions src/common/input/InputManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ class InputDeviceManager

private:
// update input for an xbox controller
bool UpdateInputXpad(std::shared_ptr<InputDevice>& Device, void* Buffer, int Direction);
bool UpdateInputXpad(std::shared_ptr<InputDevice>& Device, void* Buffer, int Direction, const std::string &Port1);
// update input for a Steel Battalion controller
bool UpdateInputSBC(std::shared_ptr<InputDevice>& Device, void* Buffer, int Direction, int Port);
bool UpdateInputSBC(std::shared_ptr<InputDevice>& Device, void* Buffer, int Direction, int Port, const std::string &Port1);
// bind a host device to an emulated device
void BindHostDevice(int type, std::string_view port);
// connect a device to the emulated machine
Expand Down
12 changes: 6 additions & 6 deletions src/common/input/InputWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ InputWindow::~InputWindow()
m_DeviceConfig = nullptr;
}

int InputWindow::IsProfileSaved()
bool InputWindow::IsProfileSaved()
{
if (m_bHasChanges) {
PopupReturn ret = PopupQuestion(m_hwnd_window, "Current configuration is not saved. Save before closing?");
Expand All @@ -53,24 +53,24 @@ int InputWindow::IsProfileSaved()
char name[50];
SendMessage(m_hwnd_profile_list, WM_GETTEXT, sizeof(name), reinterpret_cast<LPARAM>(name));
if (SaveProfile(std::string(name))) {
return EXIT_SAVE;
return true;
}
return EXIT_ABORT;
return false;
}

case PopupReturn::No: {
return EXIT_IGNORE;
return true;
}

case PopupReturn::Cancel:
default: {
return EXIT_ABORT;
return false;
}

}
}

return EXIT_IGNORE;
return true;
}

void InputWindow::UpdateDeviceList()
Expand Down
7 changes: 1 addition & 6 deletions src/common/input/InputWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
#define BUTTON_SWAP 9
#define SLOTS_CHANGED 10

#define EXIT_ABORT 0
#define EXIT_SAVE 1
#define EXIT_IGNORE 2

#define XINPUT_DEFAULT 0
#define DINPUT_DEFAULT 1

Expand All @@ -65,7 +61,7 @@ class InputWindow
virtual void ClearBindings() = 0;
virtual void UpdateProfile(const std::string& name, int command);
void UpdateCurrentDevice();
virtual int IsProfileSaved();
bool IsProfileSaved();
void SwapMoCursorAxis(Button *button);


Expand Down Expand Up @@ -111,7 +107,6 @@ class DukeInputWindow : public InputWindow
void BindDefault();
void ClearBindings() override;
void UpdateProfile(const std::string &name, int command) override;
int IsProfileSaved() override;
void SaveSlotConfig();


Expand Down
15 changes: 7 additions & 8 deletions src/common/input/SdlJoystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,19 @@ namespace Sdl
std::string port = std::to_string(*static_cast<int *>(Event.user.data1));
int port1, slot;
PortStr2Int(port, &port1, &slot);
if (g_devs[port1].type == XBOX_INPUT_DEVICE::MS_CONTROLLER_DUKE || g_devs[port1].type == XBOX_INPUT_DEVICE::MS_CONTROLLER_S) {
// Force an update of the entire slot connectivity of this port
g_InputDeviceManager.UpdateDevices(port + ".0", false);
g_InputDeviceManager.UpdateDevices(port + ".1", false);
}

g_InputDeviceManager.UpdateDevices(port, false);
// Force an update of the entire slot connectivity of this port
g_InputDeviceManager.UpdateDevices(port + ".0", false);
g_InputDeviceManager.UpdateDevices(port + ".1", false);
}

delete Event.user.data1;
delete static_cast<int *>(Event.user.data1);
Event.user.data1 = nullptr;
}
else if (Event.type == DeviceRemoveAck_t) {
g_InputDeviceManager.UpdateDevices(std::string(static_cast<char *>(Event.user.data1)), true);
delete Event.user.data1;
g_InputDeviceManager.UpdateDevices(*static_cast<std::string *>(Event.user.data1), true);
delete static_cast<std::string *>(Event.user.data1);
Event.user.data1 = nullptr;
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/common/input/SdlJoystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ namespace Sdl
}
SDL_INIT_STATUS;

struct UPDATE_INPUT_DATA {
int Port;
int Slot;
bool Opt;
};

extern uint32_t ExitEvent_t;
extern uint32_t PopulateEvent_t;
extern uint32_t UpdateInputEvent_t;
Expand Down
2 changes: 1 addition & 1 deletion src/core/hle/D3D8/Direct3D9/Direct3D9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ g_EmuCDPD;

XB_TRAMPOLINES(XB_trampoline_declare);

void LookupTrampolines()
void LookupTrampolinesD3D()
{
XB_TRAMPOLINES(XB_trampoline_lookup);
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/hle/D3D8/Direct3D9/Direct3D9.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
#define DIRECTDRAW_VERSION 0x0700
#include <ddraw.h>

extern void LookupTrampolines();
extern void LookupTrampolinesD3D();
extern void LookupTrampolinesXAPI();

// initialize render window
extern void CxbxInitWindow(bool bFullInit);
Expand Down
4 changes: 3 additions & 1 deletion src/core/hle/Patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ std::map<const std::string, const xbox_patch_t> g_PatchTable = {
PATCH_ENTRY("XSetProcessQuantumLength", xbox::EMUPATCH(XSetProcessQuantumLength), PATCH_ALWAYS),
PATCH_ENTRY("timeKillEvent", xbox::EMUPATCH(timeKillEvent), PATCH_ALWAYS),
PATCH_ENTRY("timeSetEvent", xbox::EMUPATCH(timeSetEvent), PATCH_ALWAYS),
PATCH_ENTRY("XReadMUMetaData", xbox::EMUPATCH(XReadMUMetaData), PATCH_ALWAYS),
PATCH_ENTRY("XUnmountMU", xbox::EMUPATCH(XUnmountMU), PATCH_ALWAYS),
};

Expand Down Expand Up @@ -445,7 +446,8 @@ void EmuInstallPatches()
EmuInstallPatch(it.first, it.second);
}

LookupTrampolines();
LookupTrampolinesD3D();
LookupTrampolinesXAPI();
}

void* GetPatchedFunctionTrampoline(const std::string functionName)
Expand Down

0 comments on commit de9913f

Please sign in to comment.