diff --git a/CMakeLists.txt b/CMakeLists.txt index 4df3db2b..8fcf030c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -511,6 +511,8 @@ set(VIDEO_CORE src/video_core/amdgpu/liverpool.cpp set(INPUT src/input/controller.cpp src/input/controller.h + src/input/devices/devices.h + src/input/devices/sdl_keyboard.cpp ) set(EMULATOR src/emulator.cpp diff --git a/src/input/controller.cpp b/src/input/controller.cpp index 247e08ce..b5bbdde0 100644 --- a/src/input/controller.cpp +++ b/src/input/controller.cpp @@ -10,6 +10,7 @@ namespace Input { GameController::GameController() { m_states_num = 0; m_last_state = State(); + m_device = std::make_unique(); } void GameController::ReadState(State* state, bool* isConnected, int* connectedCount) { diff --git a/src/input/controller.h b/src/input/controller.h index a16f7dd0..6aaae400 100644 --- a/src/input/controller.h +++ b/src/input/controller.h @@ -5,6 +5,7 @@ #include #include "common/types.h" +#include "devices/devices.h" namespace Input { @@ -57,6 +58,7 @@ private: u32 m_first_state = 0; std::array m_states; std::array m_private; + std::unique_ptr m_device; }; } // namespace Input diff --git a/src/input/devices/devices.h b/src/input/devices/devices.h new file mode 100644 index 00000000..bc54aed8 --- /dev/null +++ b/src/input/devices/devices.h @@ -0,0 +1,41 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include + +namespace Input { + +struct InputMappings { + using Scancode = u32; + using Container = std::unordered_map; + + u32 getMapping(Scancode scancode) const { + auto it = container.find(scancode); + return it != container.end() ? it->second : -1; + } + + void setMapping(Scancode scancode, u32 key) { + container[scancode] = key; + } + +private: + Container container; +}; + +class InputDevices { + +public: + virtual ~InputDevices() = default; + virtual InputMappings GetMappings() = 0; +}; + +class SDLKeyboard : public InputDevices { +public: + virtual ~SDLKeyboard(); + virtual InputMappings GetMappings() override; +}; + +} // namespace Input \ No newline at end of file diff --git a/src/input/devices/sdl_keyboard.cpp b/src/input/devices/sdl_keyboard.cpp new file mode 100644 index 00000000..5bd6855b --- /dev/null +++ b/src/input/devices/sdl_keyboard.cpp @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include "core/libraries/pad/pad.h" +#include "devices.h" + +namespace Input { + +SDLKeyboard::~SDLKeyboard() {} + +InputMappings SDLKeyboard::GetMappings() { + using Libraries::Pad::OrbisPadButtonDataOffset; + InputMappings mappings; + mappings.setMapping(SDLK_UP, OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_UP); + // TODO the rest + return mappings; +} +} // namespace Input \ No newline at end of file