diff options
| author | 2015-03-09 00:14:59 -0400 | |
|---|---|---|
| committer | 2015-03-10 23:58:07 -0400 | |
| commit | d61b26b79f889603a084e148626bba3c267cf75f (patch) | |
| tree | d793edd22e25a99aa5c13cc2455a5ec2167afee7 /src/core | |
| parent | EmuWindow: Made pad/touch functions non-static. (diff) | |
| download | yuzu-d61b26b79f889603a084e148626bba3c267cf75f.tar.gz yuzu-d61b26b79f889603a084e148626bba3c267cf75f.tar.xz yuzu-d61b26b79f889603a084e148626bba3c267cf75f.zip | |
HID: Complete refactor of pad/touch input to fix threading issues.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hle/service/hid/hid.cpp | 104 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.h | 35 | ||||
| -rw-r--r-- | src/core/hw/gpu.cpp | 4 |
3 files changed, 32 insertions, 111 deletions
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 703a765b5..baff92716 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -12,6 +12,8 @@ | |||
| 12 | #include "core/hle/kernel/shared_memory.h" | 12 | #include "core/hle/kernel/shared_memory.h" |
| 13 | #include "core/hle/hle.h" | 13 | #include "core/hle/hle.h" |
| 14 | 14 | ||
| 15 | #include "video_core/video_core.h" | ||
| 16 | |||
| 15 | namespace Service { | 17 | namespace Service { |
| 16 | namespace HID { | 18 | namespace HID { |
| 17 | 19 | ||
| @@ -23,15 +25,8 @@ Kernel::SharedPtr<Kernel::Event> g_event_accelerometer; | |||
| 23 | Kernel::SharedPtr<Kernel::Event> g_event_gyroscope; | 25 | Kernel::SharedPtr<Kernel::Event> g_event_gyroscope; |
| 24 | Kernel::SharedPtr<Kernel::Event> g_event_debug_pad; | 26 | Kernel::SharedPtr<Kernel::Event> g_event_debug_pad; |
| 25 | 27 | ||
| 26 | // Next Pad state update information | ||
| 27 | static PadState next_state = {{0}}; | ||
| 28 | static u32 next_pad_index = 0; | 28 | static u32 next_pad_index = 0; |
| 29 | static s16 next_pad_circle_x = 0; | ||
| 30 | static s16 next_pad_circle_y = 0; | ||
| 31 | |||
| 32 | static u32 next_touch_index = 0; | 29 | static u32 next_touch_index = 0; |
| 33 | static u16 next_touch_x = 0; | ||
| 34 | static u16 next_touch_y = 0; | ||
| 35 | 30 | ||
| 36 | /** | 31 | /** |
| 37 | * Gets a pointer to the PadData structure inside HID shared memory | 32 | * Gets a pointer to the PadData structure inside HID shared memory |
| @@ -55,38 +50,15 @@ static inline SharedMem* GetSharedMem() { | |||
| 55 | // * Set PadData.current_state.circle_left = 1 if current PadEntry.circle_pad_x <= -41 | 50 | // * Set PadData.current_state.circle_left = 1 if current PadEntry.circle_pad_x <= -41 |
| 56 | // * Set PadData.current_state.circle_right = 1 if current PadEntry.circle_pad_y <= -41 | 51 | // * Set PadData.current_state.circle_right = 1 if current PadEntry.circle_pad_y <= -41 |
| 57 | 52 | ||
| 58 | /** | 53 | void HIDUpdate() { |
| 59 | * Circle Pad from keys. | ||
| 60 | * | ||
| 61 | * This is implemented as "pushed all the way to an edge (max) or centered (0)". | ||
| 62 | * | ||
| 63 | * Indicate the circle pad is pushed completely to the edge in 1 of 8 directions. | ||
| 64 | */ | ||
| 65 | static void UpdateNextCirclePadState() { | ||
| 66 | static const s16 max_value = 0x9C; | ||
| 67 | next_pad_circle_x = next_state.circle_left ? -max_value : 0x0; | ||
| 68 | next_pad_circle_x += next_state.circle_right ? max_value : 0x0; | ||
| 69 | next_pad_circle_y = next_state.circle_down ? -max_value : 0x0; | ||
| 70 | next_pad_circle_y += next_state.circle_up ? max_value : 0x0; | ||
| 71 | } | ||
| 72 | |||
| 73 | void PadButtonPress(const PadState& pad_state) { | ||
| 74 | next_state.hex |= pad_state.hex; | ||
| 75 | UpdateNextCirclePadState(); | ||
| 76 | } | ||
| 77 | |||
| 78 | void PadButtonRelease(const PadState& pad_state) { | ||
| 79 | next_state.hex &= ~pad_state.hex; | ||
| 80 | UpdateNextCirclePadState(); | ||
| 81 | } | ||
| 82 | |||
| 83 | void PadUpdateComplete() { | ||
| 84 | SharedMem* shared_mem = GetSharedMem(); | 54 | SharedMem* shared_mem = GetSharedMem(); |
| 85 | 55 | ||
| 86 | if (shared_mem == nullptr) | 56 | if (shared_mem == nullptr) |
| 87 | return; | 57 | return; |
| 88 | 58 | ||
| 89 | shared_mem->pad.current_state.hex = next_state.hex; | 59 | const PadState& state = VideoCore::g_emu_window->GetPadState(); |
| 60 | |||
| 61 | shared_mem->pad.current_state.hex = state.hex; | ||
| 90 | shared_mem->pad.index = next_pad_index; | 62 | shared_mem->pad.index = next_pad_index; |
| 91 | ++next_touch_index %= shared_mem->pad.entries.size(); | 63 | ++next_touch_index %= shared_mem->pad.entries.size(); |
| 92 | 64 | ||
| @@ -95,28 +67,19 @@ void PadUpdateComplete() { | |||
| 95 | PadState old_state = shared_mem->pad.entries[last_entry_index].current_state; | 67 | PadState old_state = shared_mem->pad.entries[last_entry_index].current_state; |
| 96 | 68 | ||
| 97 | // Compute bitmask with 1s for bits different from the old state | 69 | // Compute bitmask with 1s for bits different from the old state |
| 98 | PadState changed; | 70 | PadState changed = { { (state.hex ^ old_state.hex) } }; |
| 99 | changed.hex = (next_state.hex ^ old_state.hex); | ||
| 100 | |||
| 101 | // Compute what was added | ||
| 102 | PadState additions; | ||
| 103 | additions.hex = changed.hex & next_state.hex; | ||
| 104 | |||
| 105 | // Compute what was removed | ||
| 106 | PadState removals; | ||
| 107 | removals.hex = changed.hex & old_state.hex; | ||
| 108 | 71 | ||
| 109 | // Get the current Pad entry | 72 | // Get the current Pad entry |
| 110 | PadDataEntry* current_pad_entry = &shared_mem->pad.entries[shared_mem->pad.index]; | 73 | PadDataEntry* pad_entry = &shared_mem->pad.entries[shared_mem->pad.index]; |
| 111 | 74 | ||
| 112 | // Update entry properties | 75 | // Update entry properties |
| 113 | current_pad_entry->current_state.hex = next_state.hex; | 76 | pad_entry->current_state.hex = state.hex; |
| 114 | current_pad_entry->delta_additions.hex = additions.hex; | 77 | pad_entry->delta_additions.hex = changed.hex & state.hex; |
| 115 | current_pad_entry->delta_removals.hex = removals.hex; | 78 | pad_entry->delta_removals.hex = changed.hex & old_state.hex;; |
| 116 | 79 | ||
| 117 | // Set circle Pad | 80 | // Set circle Pad |
| 118 | current_pad_entry->circle_pad_x = next_pad_circle_x; | 81 | pad_entry->circle_pad_x = state.circle_left ? -0x9C : state.circle_right ? 0x9C : 0x0; |
| 119 | current_pad_entry->circle_pad_y = next_pad_circle_y; | 82 | pad_entry->circle_pad_y = state.circle_down ? -0x9C : state.circle_up ? 0x9C : 0x0; |
| 120 | 83 | ||
| 121 | // If we just updated index 0, provide a new timestamp | 84 | // If we just updated index 0, provide a new timestamp |
| 122 | if (shared_mem->pad.index == 0) { | 85 | if (shared_mem->pad.index == 0) { |
| @@ -124,39 +87,15 @@ void PadUpdateComplete() { | |||
| 124 | shared_mem->pad.index_reset_ticks = (s64)Core::g_app_core->GetTicks(); | 87 | shared_mem->pad.index_reset_ticks = (s64)Core::g_app_core->GetTicks(); |
| 125 | } | 88 | } |
| 126 | 89 | ||
| 127 | // Signal both handles when there's an update to Pad or touch | ||
| 128 | g_event_pad_or_touch_1->Signal(); | ||
| 129 | g_event_pad_or_touch_2->Signal(); | ||
| 130 | } | ||
| 131 | |||
| 132 | void TouchPress(u16 x, u16 y) { | ||
| 133 | next_touch_x = x; | ||
| 134 | next_touch_y = y; | ||
| 135 | } | ||
| 136 | |||
| 137 | void TouchRelease() { | ||
| 138 | next_touch_x = 0; | ||
| 139 | next_touch_y = 0; | ||
| 140 | } | ||
| 141 | |||
| 142 | void TouchUpdateComplete() { | ||
| 143 | SharedMem* shared_mem = GetSharedMem(); | ||
| 144 | |||
| 145 | if (shared_mem == nullptr) | ||
| 146 | return; | ||
| 147 | |||
| 148 | shared_mem->touch.index = next_touch_index; | 90 | shared_mem->touch.index = next_touch_index; |
| 149 | ++next_touch_index %= shared_mem->touch.entries.size(); | 91 | ++next_touch_index %= shared_mem->touch.entries.size(); |
| 150 | 92 | ||
| 151 | // Get the current touch entry | 93 | // Get the current touch entry |
| 152 | TouchDataEntry* current_touch_entry = &shared_mem->touch.entries[shared_mem->touch.index]; | 94 | TouchDataEntry* touch_entry = &shared_mem->touch.entries[shared_mem->touch.index]; |
| 95 | bool pressed = false; | ||
| 153 | 96 | ||
| 154 | // Set touchpad position | 97 | std::tie(touch_entry->x, touch_entry->y, pressed) = VideoCore::g_emu_window->GetTouchState(); |
| 155 | current_touch_entry->x = next_touch_x; | 98 | touch_entry->valid = pressed ? 1 : 0; |
| 156 | current_touch_entry->y = next_touch_y; | ||
| 157 | |||
| 158 | // TODO(bunnei): Verify this behavior on real hardware | ||
| 159 | current_touch_entry->valid = (next_touch_x || next_touch_y) ? 1 : 0; | ||
| 160 | 99 | ||
| 161 | // TODO(bunnei): We're not doing anything with offset 0xA8 + 0x18 of HID SharedMemory, which | 100 | // TODO(bunnei): We're not doing anything with offset 0xA8 + 0x18 of HID SharedMemory, which |
| 162 | // supposedly is "Touch-screen entry, which contains the raw coordinate data prior to being | 101 | // supposedly is "Touch-screen entry, which contains the raw coordinate data prior to being |
| @@ -194,6 +133,9 @@ void HIDInit() { | |||
| 194 | 133 | ||
| 195 | g_shared_mem = SharedMemory::Create("HID:SharedMem"); | 134 | g_shared_mem = SharedMemory::Create("HID:SharedMem"); |
| 196 | 135 | ||
| 136 | next_pad_index = 0; | ||
| 137 | next_touch_index = 0; | ||
| 138 | |||
| 197 | // Create event handles | 139 | // Create event handles |
| 198 | g_event_pad_or_touch_1 = Event::Create(RESETTYPE_ONESHOT, "HID:EventPadOrTouch1"); | 140 | g_event_pad_or_touch_1 = Event::Create(RESETTYPE_ONESHOT, "HID:EventPadOrTouch1"); |
| 199 | g_event_pad_or_touch_2 = Event::Create(RESETTYPE_ONESHOT, "HID:EventPadOrTouch2"); | 141 | g_event_pad_or_touch_2 = Event::Create(RESETTYPE_ONESHOT, "HID:EventPadOrTouch2"); |
| @@ -203,8 +145,8 @@ void HIDInit() { | |||
| 203 | } | 145 | } |
| 204 | 146 | ||
| 205 | void HIDShutdown() { | 147 | void HIDShutdown() { |
| 206 | |||
| 207 | } | 148 | } |
| 208 | 149 | ||
| 209 | } | 150 | } // namespace HID |
| 210 | } | 151 | |
| 152 | } // namespace Service | ||
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 7fdf5828a..063f06858 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h | |||
| @@ -176,38 +176,13 @@ const PadState PAD_CIRCLE_DOWN = {{1u << 31}}; | |||
| 176 | */ | 176 | */ |
| 177 | void GetIPCHandles(Interface* self); | 177 | void GetIPCHandles(Interface* self); |
| 178 | 178 | ||
| 179 | /** | 179 | /// Checks for user input updates |
| 180 | * Sets a Pad state (button or button combo) as pressed | 180 | void HIDUpdate(); |
| 181 | * @param pad_state PadState data indicating which buttons have been pressed | ||
| 182 | */ | ||
| 183 | void PadButtonPress(const PadState& pad_state); | ||
| 184 | |||
| 185 | /** | ||
| 186 | * Sets a Pad state (button or button combo) as released | ||
| 187 | * @param pad_state PadState data indicating which buttons have been released | ||
| 188 | */ | ||
| 189 | void PadButtonRelease(const PadState& pad_state); | ||
| 190 | |||
| 191 | /** | ||
| 192 | * Called after all Pad changes to be included in this update have been made, including both Pad | ||
| 193 | * key changes and analog circle Pad changes. | ||
| 194 | */ | ||
| 195 | void PadUpdateComplete(); | ||
| 196 | |||
| 197 | /** | ||
| 198 | * Signal that the touchpad has been pressed | ||
| 199 | * @param x Touchpad x-coordinate in bottom screen pixels (between 0 and 320) | ||
| 200 | * @param y Touchpad y-coordinate in bottom screen pixels (between 0 and 240) | ||
| 201 | */ | ||
| 202 | void TouchPress(u16 x, u16 y); | ||
| 203 | |||
| 204 | /// Signal that touchpad has been released | ||
| 205 | void TouchRelease(); | ||
| 206 | |||
| 207 | /// Signal that touchpad updates have been completed | ||
| 208 | void TouchUpdateComplete(); | ||
| 209 | 181 | ||
| 182 | /// Initialize HID service | ||
| 210 | void HIDInit(); | 183 | void HIDInit(); |
| 184 | |||
| 185 | /// Shutdown HID service | ||
| 211 | void HIDShutdown(); | 186 | void HIDShutdown(); |
| 212 | 187 | ||
| 213 | } | 188 | } |
diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp index b7102b874..f7b822c58 100644 --- a/src/core/hw/gpu.cpp +++ b/src/core/hw/gpu.cpp | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | #include "core/hle/hle.h" | 14 | #include "core/hle/hle.h" |
| 15 | #include "core/hle/service/gsp_gpu.h" | 15 | #include "core/hle/service/gsp_gpu.h" |
| 16 | #include "core/hle/service/dsp_dsp.h" | 16 | #include "core/hle/service/dsp_dsp.h" |
| 17 | #include "core/hle/service/hid/hid.h" | ||
| 17 | 18 | ||
| 18 | #include "core/hw/gpu.h" | 19 | #include "core/hw/gpu.h" |
| 19 | 20 | ||
| @@ -294,6 +295,9 @@ static void VBlankCallback(u64 userdata, int cycles_late) { | |||
| 294 | // this. Certain games expect this to be periodically signaled. | 295 | // this. Certain games expect this to be periodically signaled. |
| 295 | DSP_DSP::SignalInterrupt(); | 296 | DSP_DSP::SignalInterrupt(); |
| 296 | 297 | ||
| 298 | // Check for user input updates | ||
| 299 | Service::HID::HIDUpdate(); | ||
| 300 | |||
| 297 | // Reschedule recurrent event | 301 | // Reschedule recurrent event |
| 298 | CoreTiming::ScheduleEvent(frame_ticks - cycles_late, vblank_event); | 302 | CoreTiming::ScheduleEvent(frame_ticks - cycles_late, vblank_event); |
| 299 | } | 303 | } |