diff options
| -rw-r--r-- | src/citra/emu_window/emu_window_glfw.cpp | 54 | ||||
| -rw-r--r-- | src/citra/emu_window/emu_window_glfw.h | 5 | ||||
| -rw-r--r-- | src/citra_qt/bootmanager.cpp | 49 | ||||
| -rw-r--r-- | src/citra_qt/bootmanager.hxx | 2 | ||||
| -rw-r--r-- | src/common/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/common/emu_window.cpp | 17 | ||||
| -rw-r--r-- | src/common/emu_window.h | 8 | ||||
| -rw-r--r-- | src/common/key_map.cpp | 25 | ||||
| -rw-r--r-- | src/common/key_map.h | 45 | ||||
| -rw-r--r-- | src/core/hle/service/hid.cpp | 145 | ||||
| -rw-r--r-- | src/core/hle/service/hid.h | 90 | ||||
| -rw-r--r-- | src/video_core/video_core.h | 1 |
12 files changed, 405 insertions, 39 deletions
diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp index 02f524e03..b911e60c5 100644 --- a/src/citra/emu_window/emu_window_glfw.cpp +++ b/src/citra/emu_window/emu_window_glfw.cpp | |||
| @@ -8,18 +8,55 @@ | |||
| 8 | 8 | ||
| 9 | #include "citra/emu_window/emu_window_glfw.h" | 9 | #include "citra/emu_window/emu_window_glfw.h" |
| 10 | 10 | ||
| 11 | static void OnKeyEvent(GLFWwindow* win, int key, int action) { | 11 | static const std::pair<int, HID_User::PadState> default_key_map[] = { |
| 12 | // TODO(bunnei): ImplementMe | 12 | { GLFW_KEY_A, HID_User::PAD_A }, |
| 13 | } | 13 | { GLFW_KEY_B, HID_User::PAD_B }, |
| 14 | { GLFW_KEY_BACKSLASH, HID_User::PAD_SELECT }, | ||
| 15 | { GLFW_KEY_ENTER, HID_User::PAD_START }, | ||
| 16 | { GLFW_KEY_RIGHT, HID_User::PAD_RIGHT }, | ||
| 17 | { GLFW_KEY_LEFT, HID_User::PAD_LEFT }, | ||
| 18 | { GLFW_KEY_UP, HID_User::PAD_UP }, | ||
| 19 | { GLFW_KEY_DOWN, HID_User::PAD_DOWN }, | ||
| 20 | { GLFW_KEY_R, HID_User::PAD_R }, | ||
| 21 | { GLFW_KEY_L, HID_User::PAD_L }, | ||
| 22 | { GLFW_KEY_X, HID_User::PAD_X }, | ||
| 23 | { GLFW_KEY_Y, HID_User::PAD_Y }, | ||
| 24 | { GLFW_KEY_H, HID_User::PAD_CIRCLE_RIGHT }, | ||
| 25 | { GLFW_KEY_F, HID_User::PAD_CIRCLE_LEFT }, | ||
| 26 | { GLFW_KEY_T, HID_User::PAD_CIRCLE_UP }, | ||
| 27 | { GLFW_KEY_G, HID_User::PAD_CIRCLE_DOWN }, | ||
| 28 | }; | ||
| 29 | |||
| 30 | /// Called by GLFW when a key event occurs | ||
| 31 | void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) { | ||
| 32 | |||
| 33 | if (!VideoCore::g_emu_window) { | ||
| 34 | return; | ||
| 35 | } | ||
| 36 | |||
| 37 | int keyboard_id = ((EmuWindow_GLFW*)VideoCore::g_emu_window)->keyboard_id; | ||
| 38 | |||
| 39 | if (action == GLFW_PRESS) { | ||
| 40 | EmuWindow::KeyPressed({key, keyboard_id}); | ||
| 41 | } | ||
| 14 | 42 | ||
| 15 | static void OnWindowSizeEvent(GLFWwindow* win, int width, int height) { | 43 | if (action == GLFW_RELEASE) { |
| 16 | EmuWindow_GLFW* emu_window = (EmuWindow_GLFW*)glfwGetWindowUserPointer(win); | 44 | EmuWindow::KeyReleased({key, keyboard_id}); |
| 17 | emu_window->SetClientAreaWidth(width); | 45 | } |
| 18 | emu_window->SetClientAreaHeight(height); | 46 | HID_User::PadUpdateComplete(); |
| 19 | } | 47 | } |
| 20 | 48 | ||
| 21 | /// EmuWindow_GLFW constructor | 49 | /// EmuWindow_GLFW constructor |
| 22 | EmuWindow_GLFW::EmuWindow_GLFW() { | 50 | EmuWindow_GLFW::EmuWindow_GLFW() { |
| 51 | |||
| 52 | // Register a new ID for the default keyboard | ||
| 53 | keyboard_id = KeyMap::NewDeviceId(); | ||
| 54 | |||
| 55 | // Set default key mappings for keyboard | ||
| 56 | for (auto mapping : default_key_map) { | ||
| 57 | KeyMap::SetKeyMapping({mapping.first, keyboard_id}, mapping.second); | ||
| 58 | } | ||
| 59 | |||
| 23 | // Initialize the window | 60 | // Initialize the window |
| 24 | if(glfwInit() != GL_TRUE) { | 61 | if(glfwInit() != GL_TRUE) { |
| 25 | printf("Failed to initialize GLFW! Exiting..."); | 62 | printf("Failed to initialize GLFW! Exiting..."); |
| @@ -45,8 +82,7 @@ EmuWindow_GLFW::EmuWindow_GLFW() { | |||
| 45 | 82 | ||
| 46 | // Setup callbacks | 83 | // Setup callbacks |
| 47 | glfwSetWindowUserPointer(m_render_window, this); | 84 | glfwSetWindowUserPointer(m_render_window, this); |
| 48 | //glfwSetKeyCallback(m_render_window, OnKeyEvent); | 85 | glfwSetKeyCallback(m_render_window, OnKeyEvent); |
| 49 | //glfwSetWindowSizeCallback(m_render_window, OnWindowSizeEvent); | ||
| 50 | 86 | ||
| 51 | DoneCurrent(); | 87 | DoneCurrent(); |
| 52 | } | 88 | } |
diff --git a/src/citra/emu_window/emu_window_glfw.h b/src/citra/emu_window/emu_window_glfw.h index c1b41203b..29325bb75 100644 --- a/src/citra/emu_window/emu_window_glfw.h +++ b/src/citra/emu_window/emu_window_glfw.h | |||
| @@ -25,8 +25,9 @@ public: | |||
| 25 | /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread | 25 | /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread |
| 26 | void DoneCurrent(); | 26 | void DoneCurrent(); |
| 27 | 27 | ||
| 28 | GLFWwindow* m_render_window; ///< Internal GLFW render window | 28 | static void OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods); |
| 29 | 29 | ||
| 30 | private: | 30 | private: |
| 31 | 31 | GLFWwindow* m_render_window; ///< Internal GLFW render window | |
| 32 | int keyboard_id; ///< Device id of keyboard for use with KeyMap | ||
| 32 | }; | 33 | }; |
diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 573060d30..657e39bea 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp | |||
| @@ -109,8 +109,35 @@ EmuThread& GRenderWindow::GetEmuThread() | |||
| 109 | return emu_thread; | 109 | return emu_thread; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | static const std::pair<int, HID_User::PadState> default_key_map[] = { | ||
| 113 | { Qt::Key_A, HID_User::PAD_A }, | ||
| 114 | { Qt::Key_B, HID_User::PAD_B }, | ||
| 115 | { Qt::Key_Backslash, HID_User::PAD_SELECT }, | ||
| 116 | { Qt::Key_Enter, HID_User::PAD_START }, | ||
| 117 | { Qt::Key_Right, HID_User::PAD_RIGHT }, | ||
| 118 | { Qt::Key_Left, HID_User::PAD_LEFT }, | ||
| 119 | { Qt::Key_Up, HID_User::PAD_UP }, | ||
| 120 | { Qt::Key_Down, HID_User::PAD_DOWN }, | ||
| 121 | { Qt::Key_R, HID_User::PAD_R }, | ||
| 122 | { Qt::Key_L, HID_User::PAD_L }, | ||
| 123 | { Qt::Key_X, HID_User::PAD_X }, | ||
| 124 | { Qt::Key_Y, HID_User::PAD_Y }, | ||
| 125 | { Qt::Key_H, HID_User::PAD_CIRCLE_RIGHT }, | ||
| 126 | { Qt::Key_F, HID_User::PAD_CIRCLE_LEFT }, | ||
| 127 | { Qt::Key_T, HID_User::PAD_CIRCLE_UP }, | ||
| 128 | { Qt::Key_G, HID_User::PAD_CIRCLE_DOWN }, | ||
| 129 | }; | ||
| 130 | |||
| 112 | GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this) | 131 | GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this) |
| 113 | { | 132 | { |
| 133 | // Register a new ID for the default keyboard | ||
| 134 | keyboard_id = KeyMap::NewDeviceId(); | ||
| 135 | |||
| 136 | // Set default key mappings for keyboard | ||
| 137 | for (auto mapping : default_key_map) { | ||
| 138 | KeyMap::SetKeyMapping({mapping.first, keyboard_id}, mapping.second); | ||
| 139 | } | ||
| 140 | |||
| 114 | // TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground, WA_DontShowOnScreen, WA_DeleteOnClose | 141 | // TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground, WA_DontShowOnScreen, WA_DeleteOnClose |
| 115 | QGLFormat fmt; | 142 | QGLFormat fmt; |
| 116 | fmt.setProfile(QGLFormat::CoreProfile); | 143 | fmt.setProfile(QGLFormat::CoreProfile); |
| @@ -209,27 +236,13 @@ QByteArray GRenderWindow::saveGeometry() | |||
| 209 | 236 | ||
| 210 | void GRenderWindow::keyPressEvent(QKeyEvent* event) | 237 | void GRenderWindow::keyPressEvent(QKeyEvent* event) |
| 211 | { | 238 | { |
| 212 | /* | 239 | EmuWindow::KeyPressed({event->key(), keyboard_id}); |
| 213 | bool key_processed = false; | 240 | HID_User::PadUpdateComplete(); |
| 214 | for (unsigned int channel = 0; channel < 4 && controller_interface(); ++channel) | ||
| 215 | if (controller_interface()->SetControllerStatus(channel, event->key(), input_common::GCController::PRESSED)) | ||
| 216 | key_processed = true; | ||
| 217 | |||
| 218 | if (!key_processed) | ||
| 219 | QWidget::keyPressEvent(event); | ||
| 220 | */ | ||
| 221 | } | 241 | } |
| 222 | 242 | ||
| 223 | void GRenderWindow::keyReleaseEvent(QKeyEvent* event) | 243 | void GRenderWindow::keyReleaseEvent(QKeyEvent* event) |
| 224 | { | 244 | { |
| 225 | /* | 245 | EmuWindow::KeyReleased({event->key(), keyboard_id}); |
| 226 | bool key_processed = false; | 246 | HID_User::PadUpdateComplete(); |
| 227 | for (unsigned int channel = 0; channel < 4 && controller_interface(); ++channel) | ||
| 228 | if (controller_interface()->SetControllerStatus(channel, event->key(), input_common::GCController::RELEASED)) | ||
| 229 | key_processed = true; | ||
| 230 | |||
| 231 | if (!key_processed) | ||
| 232 | QWidget::keyPressEvent(event); | ||
| 233 | */ | ||
| 234 | } | 247 | } |
| 235 | 248 | ||
diff --git a/src/citra_qt/bootmanager.hxx b/src/citra_qt/bootmanager.hxx index 51cb781e9..eedf19471 100644 --- a/src/citra_qt/bootmanager.hxx +++ b/src/citra_qt/bootmanager.hxx | |||
| @@ -116,4 +116,6 @@ private: | |||
| 116 | EmuThread emu_thread; | 116 | EmuThread emu_thread; |
| 117 | 117 | ||
| 118 | QByteArray geometry; | 118 | QByteArray geometry; |
| 119 | |||
| 120 | int keyboard_id; | ||
| 119 | }; | 121 | }; |
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 3a82f5b80..9d5a90762 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -4,10 +4,12 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scm_rev.cpp.in" "${CMAKE_CURRENT_SOU | |||
| 4 | set(SRCS | 4 | set(SRCS |
| 5 | break_points.cpp | 5 | break_points.cpp |
| 6 | console_listener.cpp | 6 | console_listener.cpp |
| 7 | emu_window.cpp | ||
| 7 | extended_trace.cpp | 8 | extended_trace.cpp |
| 8 | file_search.cpp | 9 | file_search.cpp |
| 9 | file_util.cpp | 10 | file_util.cpp |
| 10 | hash.cpp | 11 | hash.cpp |
| 12 | key_map.cpp | ||
| 11 | log_manager.cpp | 13 | log_manager.cpp |
| 12 | math_util.cpp | 14 | math_util.cpp |
| 13 | mem_arena.cpp | 15 | mem_arena.cpp |
| @@ -39,6 +41,7 @@ set(HEADERS | |||
| 39 | file_search.h | 41 | file_search.h |
| 40 | file_util.h | 42 | file_util.h |
| 41 | hash.h | 43 | hash.h |
| 44 | key_map.h | ||
| 42 | linear_disk_cache.h | 45 | linear_disk_cache.h |
| 43 | log.h | 46 | log.h |
| 44 | log_manager.h | 47 | log_manager.h |
diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp new file mode 100644 index 000000000..7a2c50ac8 --- /dev/null +++ b/src/common/emu_window.cpp | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "emu_window.h" | ||
| 6 | |||
| 7 | void EmuWindow::KeyPressed(KeyMap::HostDeviceKey key) { | ||
| 8 | HID_User::PadState mapped_key = KeyMap::GetPadKey(key); | ||
| 9 | |||
| 10 | HID_User::PadButtonPress(mapped_key); | ||
| 11 | } | ||
| 12 | |||
| 13 | void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) { | ||
| 14 | HID_User::PadState mapped_key = KeyMap::GetPadKey(key); | ||
| 15 | |||
| 16 | HID_User::PadButtonRelease(mapped_key); | ||
| 17 | } | ||
diff --git a/src/common/emu_window.h b/src/common/emu_window.h index 5e2c33d7a..23f178fdf 100644 --- a/src/common/emu_window.h +++ b/src/common/emu_window.h | |||
| @@ -7,6 +7,8 @@ | |||
| 7 | #include "common/common.h" | 7 | #include "common/common.h" |
| 8 | #include "common/scm_rev.h" | 8 | #include "common/scm_rev.h" |
| 9 | 9 | ||
| 10 | #include "common/key_map.h" | ||
| 11 | |||
| 10 | // Abstraction class used to provide an interface between emulation code and the frontend (e.g. SDL, | 12 | // Abstraction class used to provide an interface between emulation code and the frontend (e.g. SDL, |
| 11 | // QGLWidget, GLFW, etc...) | 13 | // QGLWidget, GLFW, etc...) |
| 12 | class EmuWindow | 14 | class EmuWindow |
| @@ -32,6 +34,12 @@ public: | |||
| 32 | /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread | 34 | /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread |
| 33 | virtual void DoneCurrent() = 0; | 35 | virtual void DoneCurrent() = 0; |
| 34 | 36 | ||
| 37 | /// Signals a key press action to the HID module | ||
| 38 | static void KeyPressed(KeyMap::HostDeviceKey key); | ||
| 39 | |||
| 40 | /// Signals a key release action to the HID module | ||
| 41 | static void KeyReleased(KeyMap::HostDeviceKey key); | ||
| 42 | |||
| 35 | Config GetConfig() const { | 43 | Config GetConfig() const { |
| 36 | return m_config; | 44 | return m_config; |
| 37 | } | 45 | } |
diff --git a/src/common/key_map.cpp b/src/common/key_map.cpp new file mode 100644 index 000000000..309caab98 --- /dev/null +++ b/src/common/key_map.cpp | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "key_map.h" | ||
| 6 | #include <map> | ||
| 7 | |||
| 8 | namespace KeyMap { | ||
| 9 | |||
| 10 | static std::map<HostDeviceKey, HID_User::PadState> key_map; | ||
| 11 | static int next_device_id = 0; | ||
| 12 | |||
| 13 | int NewDeviceId() { | ||
| 14 | return next_device_id++; | ||
| 15 | } | ||
| 16 | |||
| 17 | void SetKeyMapping(HostDeviceKey key, HID_User::PadState padState) { | ||
| 18 | key_map[key].hex = padState.hex; | ||
| 19 | } | ||
| 20 | |||
| 21 | HID_User::PadState GetPadKey(HostDeviceKey key) { | ||
| 22 | return key_map[key]; | ||
| 23 | } | ||
| 24 | |||
| 25 | } | ||
diff --git a/src/common/key_map.h b/src/common/key_map.h new file mode 100644 index 000000000..b5acfbab0 --- /dev/null +++ b/src/common/key_map.h | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "core/hle/service/hid.h" | ||
| 8 | |||
| 9 | namespace KeyMap { | ||
| 10 | |||
| 11 | /** | ||
| 12 | * Represents a key for a specific host device. | ||
| 13 | */ | ||
| 14 | struct HostDeviceKey { | ||
| 15 | int key_code; | ||
| 16 | int device_id; ///< Uniquely identifies a host device | ||
| 17 | |||
| 18 | bool operator < (const HostDeviceKey &other) const { | ||
| 19 | if (device_id == other.device_id) { | ||
| 20 | return key_code < other.key_code; | ||
| 21 | } | ||
| 22 | return device_id < other.device_id; | ||
| 23 | } | ||
| 24 | |||
| 25 | bool operator == (const HostDeviceKey &other) const { | ||
| 26 | return device_id == other.device_id && key_code == other.key_code; | ||
| 27 | } | ||
| 28 | }; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * Generates a new device id, which uniquely identifies a host device within KeyMap. | ||
| 32 | */ | ||
| 33 | int NewDeviceId(); | ||
| 34 | |||
| 35 | /** | ||
| 36 | * Maps a device-specific key to a PadState. | ||
| 37 | */ | ||
| 38 | void SetKeyMapping(HostDeviceKey key, HID_User::PadState padState); | ||
| 39 | |||
| 40 | /** | ||
| 41 | * Gets the PadState that's mapped to the provided device-specific key. | ||
| 42 | */ | ||
| 43 | HID_User::PadState GetPadKey(HostDeviceKey key); | ||
| 44 | |||
| 45 | } | ||
diff --git a/src/core/hle/service/hid.cpp b/src/core/hle/service/hid.cpp index 4e470795f..b6ec1b8ff 100644 --- a/src/core/hle/service/hid.cpp +++ b/src/core/hle/service/hid.cpp | |||
| @@ -14,7 +14,128 @@ | |||
| 14 | 14 | ||
| 15 | namespace HID_User { | 15 | namespace HID_User { |
| 16 | 16 | ||
| 17 | Handle g_shared_mem = 0; ///< Handle to shared memory region designated to HID_User service | 17 | // Handle to shared memory region designated to HID_User service |
| 18 | static Handle shared_mem = 0; | ||
| 19 | |||
| 20 | // Event handles | ||
| 21 | static Handle event_pad_or_touch_1 = 0; | ||
| 22 | static Handle event_pad_or_touch_2 = 0; | ||
| 23 | static Handle event_accelerometer = 0; | ||
| 24 | static Handle event_gyroscope = 0; | ||
| 25 | static Handle event_debug_pad = 0; | ||
| 26 | |||
| 27 | // Next Pad state update information | ||
| 28 | static PadState next_state = {{0}}; | ||
| 29 | static u32 next_index = 0; | ||
| 30 | static s16 next_circle_x = 0; | ||
| 31 | static s16 next_circle_y = 0; | ||
| 32 | |||
| 33 | /** | ||
| 34 | * Gets a pointer to the PadData structure inside HID shared memory | ||
| 35 | */ | ||
| 36 | static inline PadData* GetPadData() { | ||
| 37 | if (0 == shared_mem) | ||
| 38 | return nullptr; | ||
| 39 | |||
| 40 | return reinterpret_cast<PadData*>(Kernel::GetSharedMemoryPointer(shared_mem, 0)); | ||
| 41 | } | ||
| 42 | |||
| 43 | /** | ||
| 44 | * Circle Pad from keys. | ||
| 45 | * | ||
| 46 | * This is implemented as "pushed all the way to an edge (max) or centered (0)". | ||
| 47 | * | ||
| 48 | * Indicate the circle pad is pushed completely to the edge in 1 of 8 directions. | ||
| 49 | */ | ||
| 50 | void UpdateNextCirclePadState() { | ||
| 51 | static const s16 max_value = 0x9C; | ||
| 52 | next_circle_x = next_state.circle_left ? -max_value : 0x0; | ||
| 53 | next_circle_x += next_state.circle_right ? max_value : 0x0; | ||
| 54 | next_circle_y = next_state.circle_down ? -max_value : 0x0; | ||
| 55 | next_circle_y += next_state.circle_up ? max_value : 0x0; | ||
| 56 | } | ||
| 57 | |||
| 58 | /** | ||
| 59 | * Sets a Pad state (button or button combo) as pressed | ||
| 60 | */ | ||
| 61 | void PadButtonPress(PadState pad_state) { | ||
| 62 | next_state.hex |= pad_state.hex; | ||
| 63 | UpdateNextCirclePadState(); | ||
| 64 | } | ||
| 65 | |||
| 66 | /** | ||
| 67 | * Sets a Pad state (button or button combo) as released | ||
| 68 | */ | ||
| 69 | void PadButtonRelease(PadState pad_state) { | ||
| 70 | next_state.hex &= ~pad_state.hex; | ||
| 71 | UpdateNextCirclePadState(); | ||
| 72 | } | ||
| 73 | |||
| 74 | /** | ||
| 75 | * Called after all Pad changes to be included in this update have been made, | ||
| 76 | * including both Pad key changes and analog circle Pad changes. | ||
| 77 | */ | ||
| 78 | void PadUpdateComplete() { | ||
| 79 | PadData* pad_data = GetPadData(); | ||
| 80 | |||
| 81 | // Update PadData struct | ||
| 82 | pad_data->current_state.hex = next_state.hex; | ||
| 83 | pad_data->index = next_index; | ||
| 84 | next_index = (next_index + 1) % pad_data->entries.size(); | ||
| 85 | |||
| 86 | // Get the previous Pad state | ||
| 87 | u32 last_entry_index = (pad_data->index - 1) % pad_data->entries.size(); | ||
| 88 | PadState old_state = pad_data->entries[last_entry_index].current_state; | ||
| 89 | |||
| 90 | // Compute bitmask with 1s for bits different from the old state | ||
| 91 | PadState changed; | ||
| 92 | changed.hex = (next_state.hex ^ old_state.hex); | ||
| 93 | |||
| 94 | // Compute what was added | ||
| 95 | PadState additions; | ||
| 96 | additions.hex = changed.hex & next_state.hex; | ||
| 97 | |||
| 98 | // Compute what was removed | ||
| 99 | PadState removals; | ||
| 100 | removals.hex = changed.hex & old_state.hex; | ||
| 101 | |||
| 102 | // Get the current Pad entry | ||
| 103 | PadDataEntry* current_pad_entry = &pad_data->entries[pad_data->index]; | ||
| 104 | |||
| 105 | // Update entry properties | ||
| 106 | current_pad_entry->current_state.hex = next_state.hex; | ||
| 107 | current_pad_entry->delta_additions.hex = additions.hex; | ||
| 108 | current_pad_entry->delta_removals.hex = removals.hex; | ||
| 109 | |||
| 110 | // Set circle Pad | ||
| 111 | current_pad_entry->circle_pad_x = next_circle_x; | ||
| 112 | current_pad_entry->circle_pad_y = next_circle_y; | ||
| 113 | |||
| 114 | // If we just updated index 0, provide a new timestamp | ||
| 115 | if (pad_data->index == 0) { | ||
| 116 | pad_data->index_reset_ticks_previous = pad_data->index_reset_ticks; | ||
| 117 | pad_data->index_reset_ticks = (s64)Core::g_app_core->GetTicks(); | ||
| 118 | } | ||
| 119 | |||
| 120 | // Signal both handles when there's an update to Pad or touch | ||
| 121 | Kernel::SignalEvent(event_pad_or_touch_1); | ||
| 122 | Kernel::SignalEvent(event_pad_or_touch_2); | ||
| 123 | } | ||
| 124 | |||
| 125 | |||
| 126 | // TODO(peachum): | ||
| 127 | // Add a method for setting analog input from joystick device for the circle Pad. | ||
| 128 | // | ||
| 129 | // This method should: | ||
| 130 | // * Be called after both PadButton<Press, Release>(). | ||
| 131 | // * Be called before PadUpdateComplete() | ||
| 132 | // * Set current PadEntry.circle_pad_<axis> using analog data | ||
| 133 | // * Set PadData.raw_circle_pad_data | ||
| 134 | // * Set PadData.current_state.circle_right = 1 if current PadEntry.circle_pad_x >= 41 | ||
| 135 | // * Set PadData.current_state.circle_up = 1 if current PadEntry.circle_pad_y >= 41 | ||
| 136 | // * Set PadData.current_state.circle_left = 1 if current PadEntry.circle_pad_x <= -41 | ||
| 137 | // * Set PadData.current_state.circle_right = 1 if current PadEntry.circle_pad_y <= -41 | ||
| 138 | |||
| 18 | 139 | ||
| 19 | /** | 140 | /** |
| 20 | * HID_User::GetIPCHandles service function | 141 | * HID_User::GetIPCHandles service function |
| @@ -34,12 +155,12 @@ void GetIPCHandles(Service::Interface* self) { | |||
| 34 | u32* cmd_buff = Service::GetCommandBuffer(); | 155 | u32* cmd_buff = Service::GetCommandBuffer(); |
| 35 | 156 | ||
| 36 | cmd_buff[1] = 0; // No error | 157 | cmd_buff[1] = 0; // No error |
| 37 | cmd_buff[3] = g_shared_mem; | 158 | cmd_buff[3] = shared_mem; |
| 38 | cmd_buff[4] = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventA"); | 159 | cmd_buff[4] = event_pad_or_touch_1; |
| 39 | cmd_buff[5] = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventB"); | 160 | cmd_buff[5] = event_pad_or_touch_2; |
| 40 | cmd_buff[6] = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventC"); | 161 | cmd_buff[6] = event_accelerometer; |
| 41 | cmd_buff[7] = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventGyroscope"); | 162 | cmd_buff[7] = event_gyroscope; |
| 42 | cmd_buff[8] = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventD"); | 163 | cmd_buff[8] = event_debug_pad; |
| 43 | 164 | ||
| 44 | DEBUG_LOG(KERNEL, "called"); | 165 | DEBUG_LOG(KERNEL, "called"); |
| 45 | } | 166 | } |
| @@ -57,11 +178,19 @@ const Interface::FunctionInfo FunctionTable[] = { | |||
| 57 | {0x00170000, nullptr, "GetSoundVolume"}, | 178 | {0x00170000, nullptr, "GetSoundVolume"}, |
| 58 | }; | 179 | }; |
| 59 | 180 | ||
| 181 | |||
| 60 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 182 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 61 | // Interface class | 183 | // Interface class |
| 62 | 184 | ||
| 63 | Interface::Interface() { | 185 | Interface::Interface() { |
| 64 | g_shared_mem = Kernel::CreateSharedMemory("HID_User:SharedMem"); // Create shared memory object | 186 | shared_mem = Kernel::CreateSharedMemory("HID_User:SharedMem"); // Create shared memory object |
| 187 | |||
| 188 | // Create event handles | ||
| 189 | event_pad_or_touch_1 = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventPadOrTouch1"); | ||
| 190 | event_pad_or_touch_2 = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventPadOrTouch2"); | ||
| 191 | event_accelerometer = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventAccelerometer"); | ||
| 192 | event_gyroscope = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventGyroscope"); | ||
| 193 | event_debug_pad = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventDebugPad"); | ||
| 65 | 194 | ||
| 66 | Register(FunctionTable, ARRAY_SIZE(FunctionTable)); | 195 | Register(FunctionTable, ARRAY_SIZE(FunctionTable)); |
| 67 | } | 196 | } |
diff --git a/src/core/hle/service/hid.h b/src/core/hle/service/hid.h index b17fcfa86..a077e25cd 100644 --- a/src/core/hle/service/hid.h +++ b/src/core/hle/service/hid.h | |||
| @@ -5,15 +5,101 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "core/hle/service/service.h" | 7 | #include "core/hle/service/service.h" |
| 8 | #include "common/bit_field.h" | ||
| 8 | 9 | ||
| 9 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 10 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 10 | // Namespace HID_User | 11 | // Namespace HID_User |
| 11 | 12 | ||
| 12 | // This service is used for interfacing to physical user controls... perhaps "Human Interface | 13 | // This service is used for interfacing to physical user controls. |
| 13 | // Devices"? Uses include game pad controls, accelerometers, gyroscopes, etc. | 14 | // Uses include game pad controls, touchscreen, accelerometers, gyroscopes, and debug pad. |
| 14 | 15 | ||
| 15 | namespace HID_User { | 16 | namespace HID_User { |
| 16 | 17 | ||
| 18 | /** | ||
| 19 | * Structure of a Pad controller state. | ||
| 20 | */ | ||
| 21 | struct PadState { | ||
| 22 | union { | ||
| 23 | u32 hex; | ||
| 24 | |||
| 25 | BitField<0, 1, u32> a; | ||
| 26 | BitField<1, 1, u32> b; | ||
| 27 | BitField<2, 1, u32> select; | ||
| 28 | BitField<3, 1, u32> start; | ||
| 29 | BitField<4, 1, u32> right; | ||
| 30 | BitField<5, 1, u32> left; | ||
| 31 | BitField<6, 1, u32> up; | ||
| 32 | BitField<7, 1, u32> down; | ||
| 33 | BitField<8, 1, u32> r; | ||
| 34 | BitField<9, 1, u32> l; | ||
| 35 | BitField<10, 1, u32> x; | ||
| 36 | BitField<11, 1, u32> y; | ||
| 37 | |||
| 38 | BitField<28, 1, u32> circle_right; | ||
| 39 | BitField<29, 1, u32> circle_left; | ||
| 40 | BitField<30, 1, u32> circle_up; | ||
| 41 | BitField<31, 1, u32> circle_down; | ||
| 42 | }; | ||
| 43 | }; | ||
| 44 | |||
| 45 | /** | ||
| 46 | * Structure of a single entry in the PadData's Pad state history array. | ||
| 47 | */ | ||
| 48 | struct PadDataEntry { | ||
| 49 | PadState current_state; | ||
| 50 | PadState delta_additions; | ||
| 51 | PadState delta_removals; | ||
| 52 | |||
| 53 | s16 circle_pad_x; | ||
| 54 | s16 circle_pad_y; | ||
| 55 | }; | ||
| 56 | |||
| 57 | /** | ||
| 58 | * Structure of all data related to the 3DS Pad. | ||
| 59 | */ | ||
| 60 | struct PadData { | ||
| 61 | s64 index_reset_ticks; | ||
| 62 | s64 index_reset_ticks_previous; | ||
| 63 | u32 index; // the index of the last updated Pad state history element | ||
| 64 | |||
| 65 | u32 pad1; | ||
| 66 | u32 pad2; | ||
| 67 | |||
| 68 | PadState current_state; // same as entries[index].current_state | ||
| 69 | u32 raw_circle_pad_data; | ||
| 70 | |||
| 71 | u32 pad3; | ||
| 72 | |||
| 73 | std::array<PadDataEntry, 8> entries; // Pad state history | ||
| 74 | }; | ||
| 75 | |||
| 76 | // Pre-defined PadStates for single button presses | ||
| 77 | const PadState PAD_NONE = {{0}}; | ||
| 78 | const PadState PAD_A = {{1u << 0}}; | ||
| 79 | const PadState PAD_B = {{1u << 1}}; | ||
| 80 | const PadState PAD_SELECT = {{1u << 2}}; | ||
| 81 | const PadState PAD_START = {{1u << 3}}; | ||
| 82 | const PadState PAD_RIGHT = {{1u << 4}}; | ||
| 83 | const PadState PAD_LEFT = {{1u << 5}}; | ||
| 84 | const PadState PAD_UP = {{1u << 6}}; | ||
| 85 | const PadState PAD_DOWN = {{1u << 7}}; | ||
| 86 | const PadState PAD_R = {{1u << 8}}; | ||
| 87 | const PadState PAD_L = {{1u << 9}}; | ||
| 88 | const PadState PAD_X = {{1u << 10}}; | ||
| 89 | const PadState PAD_Y = {{1u << 11}}; | ||
| 90 | const PadState PAD_CIRCLE_RIGHT = {{1u << 28}}; | ||
| 91 | const PadState PAD_CIRCLE_LEFT = {{1u << 29}}; | ||
| 92 | const PadState PAD_CIRCLE_UP = {{1u << 30}}; | ||
| 93 | const PadState PAD_CIRCLE_DOWN = {{1u << 31}}; | ||
| 94 | |||
| 95 | // Methods for updating the HID module's state | ||
| 96 | void PadButtonPress(PadState pad_state); | ||
| 97 | void PadButtonRelease(PadState pad_state); | ||
| 98 | void PadUpdateComplete(); | ||
| 99 | |||
| 100 | /** | ||
| 101 | * HID service interface. | ||
| 102 | */ | ||
| 17 | class Interface : public Service::Interface { | 103 | class Interface : public Service::Interface { |
| 18 | public: | 104 | public: |
| 19 | 105 | ||
diff --git a/src/video_core/video_core.h b/src/video_core/video_core.h index d227b6aa4..5e8129b5a 100644 --- a/src/video_core/video_core.h +++ b/src/video_core/video_core.h | |||
| @@ -27,6 +27,7 @@ static const int kScreenBottomHeight = 240; ///< 3DS bottom screen height | |||
| 27 | 27 | ||
| 28 | extern RendererBase* g_renderer; ///< Renderer plugin | 28 | extern RendererBase* g_renderer; ///< Renderer plugin |
| 29 | extern int g_current_frame; ///< Current frame | 29 | extern int g_current_frame; ///< Current frame |
| 30 | extern EmuWindow* g_emu_window; ///< Emu window | ||
| 30 | 31 | ||
| 31 | /// Start the video core | 32 | /// Start the video core |
| 32 | void Start(); | 33 | void Start(); |