summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2015-03-09 00:14:59 -0400
committerGravatar bunnei2015-03-10 23:58:07 -0400
commitd61b26b79f889603a084e148626bba3c267cf75f (patch)
treed793edd22e25a99aa5c13cc2455a5ec2167afee7 /src
parentEmuWindow: Made pad/touch functions non-static. (diff)
downloadyuzu-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')
-rw-r--r--src/citra/emu_window/emu_window_glfw.cpp17
-rw-r--r--src/citra_qt/bootmanager.cpp22
-rw-r--r--src/common/emu_window.cpp74
-rw-r--r--src/common/emu_window.h57
-rw-r--r--src/core/hle/service/hid/hid.cpp104
-rw-r--r--src/core/hle/service/hid/hid.h35
-rw-r--r--src/core/hw/gpu.cpp4
7 files changed, 109 insertions, 204 deletions
diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp
index 3e58d6663..997e3bc7d 100644
--- a/src/citra/emu_window/emu_window_glfw.cpp
+++ b/src/citra/emu_window/emu_window_glfw.cpp
@@ -23,18 +23,15 @@ void EmuWindow_GLFW::OnMouseButtonEvent(GLFWwindow* win, int button, int action,
23 double x, y; 23 double x, y;
24 glfwGetCursorPos(win, &x, &y); 24 glfwGetCursorPos(win, &x, &y);
25 25
26 if (action == GLFW_PRESS) { 26 if (action == GLFW_PRESS)
27 emu_window->TouchPressed(layout, static_cast<u16>(x), static_cast<u16>(y)); 27 emu_window->TouchPressed(static_cast<unsigned>(x), static_cast<unsigned>(y));
28 } else if (action == GLFW_RELEASE) { 28 else if (action == GLFW_RELEASE)
29 emu_window->TouchReleased(layout, static_cast<u16>(x), static_cast<u16>(y)); 29 emu_window->TouchReleased();
30 }
31 } 30 }
32} 31}
33 32
34void EmuWindow_GLFW::OnCursorPosEvent(GLFWwindow* win, double x, double y) { 33void EmuWindow_GLFW::OnCursorPosEvent(GLFWwindow* win, double x, double y) {
35 auto emu_window = GetEmuWindow(win); 34 GetEmuWindow(win)->TouchMoved(static_cast<unsigned>(x), static_cast<unsigned>(y));
36 auto layout = emu_window->GetFramebufferLayout();
37 emu_window->TouchMoved(layout, static_cast<u16>(x), static_cast<u16>(y));
38} 35}
39 36
40/// Called by GLFW when a key event occurs 37/// Called by GLFW when a key event occurs
@@ -45,10 +42,8 @@ void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int acti
45 if (action == GLFW_PRESS) { 42 if (action == GLFW_PRESS) {
46 emu_window->KeyPressed({key, keyboard_id}); 43 emu_window->KeyPressed({key, keyboard_id});
47 } else if (action == GLFW_RELEASE) { 44 } else if (action == GLFW_RELEASE) {
48 emu_window->KeyReleased({ key, keyboard_id }); 45 emu_window->KeyReleased({key, keyboard_id});
49 } 46 }
50
51 Service::HID::PadUpdateComplete();
52} 47}
53 48
54/// Whether the window is still open, and a close request hasn't yet been sent 49/// Whether the window is still open, and a close request hasn't yet been sent
diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp
index cf07e65cc..b81bd6167 100644
--- a/src/citra_qt/bootmanager.cpp
+++ b/src/citra_qt/bootmanager.cpp
@@ -268,39 +268,33 @@ QByteArray GRenderWindow::saveGeometry()
268 268
269void GRenderWindow::keyPressEvent(QKeyEvent* event) 269void GRenderWindow::keyPressEvent(QKeyEvent* event)
270{ 270{
271 EmuWindow::KeyPressed({event->key(), keyboard_id}); 271 this->KeyPressed({event->key(), keyboard_id});
272 Service::HID::PadUpdateComplete();
273} 272}
274 273
275void GRenderWindow::keyReleaseEvent(QKeyEvent* event) 274void GRenderWindow::keyReleaseEvent(QKeyEvent* event)
276{ 275{
277 EmuWindow::KeyReleased({event->key(), keyboard_id}); 276 this->KeyReleased({event->key(), keyboard_id});
278 Service::HID::PadUpdateComplete();
279} 277}
280 278
281void GRenderWindow::mousePressEvent(QMouseEvent *event) 279void GRenderWindow::mousePressEvent(QMouseEvent *event)
282{ 280{
283 if (event->button() == Qt::LeftButton) { 281 if (event->button() == Qt::LeftButton)
282 {
284 auto pos = event->pos(); 283 auto pos = event->pos();
285 EmuWindow::TouchPressed(GetFramebufferLayout(), static_cast<u16>(pos.x()), 284 this->TouchPressed(static_cast<unsigned>(pos.x()), static_cast<unsigned>(pos.y()));
286 static_cast<u16>(pos.y()));
287 } 285 }
288} 286}
289 287
290void GRenderWindow::mouseMoveEvent(QMouseEvent *event) 288void GRenderWindow::mouseMoveEvent(QMouseEvent *event)
291{ 289{
292 auto pos = event->pos(); 290 auto pos = event->pos();
293 EmuWindow::TouchMoved(GetFramebufferLayout(), static_cast<u16>(pos.x()), 291 this->TouchMoved(static_cast<unsigned>(pos.x()), static_cast<unsigned>(pos.y()));
294 static_cast<u16>(pos.y()));
295} 292}
296 293
297void GRenderWindow::mouseReleaseEvent(QMouseEvent *event) 294void GRenderWindow::mouseReleaseEvent(QMouseEvent *event)
298{ 295{
299 if (event->button() == Qt::LeftButton) { 296 if (event->button() == Qt::LeftButton)
300 auto pos = event->pos(); 297 this->TouchReleased();
301 EmuWindow::TouchReleased(GetFramebufferLayout(), static_cast<u16>(pos.x()),
302 static_cast<u16>(pos.y()));
303 }
304} 298}
305 299
306void GRenderWindow::ReloadSetKeymaps() 300void GRenderWindow::ReloadSetKeymaps()
diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp
index 89bb89481..6516fc633 100644
--- a/src/common/emu_window.cpp
+++ b/src/common/emu_window.cpp
@@ -6,15 +6,11 @@
6#include "video_core/video_core.h" 6#include "video_core/video_core.h"
7 7
8void EmuWindow::KeyPressed(KeyMap::HostDeviceKey key) { 8void EmuWindow::KeyPressed(KeyMap::HostDeviceKey key) {
9 Service::HID::PadState mapped_key = KeyMap::GetPadKey(key); 9 pad_state.hex |= KeyMap::GetPadKey(key).hex;
10
11 Service::HID::PadButtonPress(mapped_key);
12} 10}
13 11
14void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) { 12void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) {
15 Service::HID::PadState mapped_key = KeyMap::GetPadKey(key); 13 pad_state.hex &= ~KeyMap::GetPadKey(key).hex;
16
17 Service::HID::PadButtonRelease(mapped_key);
18} 14}
19 15
20/** 16/**
@@ -25,55 +21,41 @@ void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) {
25 * @return True if the coordinates are within the touchpad, otherwise false 21 * @return True if the coordinates are within the touchpad, otherwise false
26 */ 22 */
27static bool IsWithinTouchscreen(const EmuWindow::FramebufferLayout& layout, unsigned framebuffer_x, 23static bool IsWithinTouchscreen(const EmuWindow::FramebufferLayout& layout, unsigned framebuffer_x,
28 unsigned framebuffer_y) { 24 unsigned framebuffer_y) {
29 25 return (framebuffer_y >= layout.bottom_screen.top &&
30 return (framebuffer_y >= layout.bottom_screen.top && 26 framebuffer_y < layout.bottom_screen.bottom &&
31 framebuffer_y < layout.bottom_screen.bottom && 27 framebuffer_x >= layout.bottom_screen.left &&
32 framebuffer_x >= layout.bottom_screen.left && 28 framebuffer_x < layout.bottom_screen.right);
33 framebuffer_x < layout.bottom_screen.right);
34} 29}
35 30
36void EmuWindow::TouchPressed(const FramebufferLayout& layout, unsigned framebuffer_x, 31void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) {
37 unsigned framebuffer_y) { 32 if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y))
33 return;
38 34
39 if (IsWithinTouchscreen(layout, framebuffer_x, framebuffer_y)) { 35 touch_x = VideoCore::kScreenBottomWidth * (framebuffer_x - framebuffer_layout.bottom_screen.left) /
40 u16 touch_x = VideoCore::kScreenBottomWidth * (framebuffer_x - layout.bottom_screen.left) / 36 (framebuffer_layout.bottom_screen.right - framebuffer_layout.bottom_screen.left);
41 (layout.bottom_screen.right - layout.bottom_screen.left); 37 touch_y = VideoCore::kScreenBottomHeight * (framebuffer_y - framebuffer_layout.bottom_screen.top) /
42 u16 touch_y = VideoCore::kScreenBottomHeight * (framebuffer_y - layout.bottom_screen.top) / 38 (framebuffer_layout.bottom_screen.bottom - framebuffer_layout.bottom_screen.top);
43 (layout.bottom_screen.bottom - layout.bottom_screen.top);
44 39
45 Service::HID::TouchPress(touch_x, touch_y); 40 touch_pressed = true;
46 Service::HID::TouchUpdateComplete(); 41 pad_state.touch = 1;
47
48 touch_pressed = true;
49 }
50} 42}
51 43
52void EmuWindow::TouchReleased(const FramebufferLayout& layout, unsigned framebuffer_x, 44void EmuWindow::TouchReleased() {
53 unsigned framebuffer_y) { 45 touch_pressed = false;
54 46 touch_x = 0;
55 if (IsWithinTouchscreen(layout, framebuffer_x, framebuffer_y)) { 47 touch_y = 0;
56 48 pad_state.touch = 0;
57 Service::HID::TouchRelease();
58 Service::HID::TouchUpdateComplete();
59
60 touch_pressed = false;
61 }
62} 49}
63 50
64void EmuWindow::TouchMoved(const FramebufferLayout& layout, unsigned framebuffer_x, 51void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) {
65 unsigned framebuffer_y) { 52 if (!touch_pressed)
53 return;
66 54
67 if (touch_pressed) { 55 if (IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y))
68 if (IsWithinTouchscreen(layout, framebuffer_x, framebuffer_y)) { 56 TouchPressed(framebuffer_x, framebuffer_y);
69 EmuWindow::TouchPressed(layout, framebuffer_x, framebuffer_y); 57 else
70 } else { 58 TouchReleased();
71 Service::HID::TouchRelease();
72 Service::HID::TouchUpdateComplete();
73
74 touch_pressed = false;
75 }
76 }
77} 59}
78 60
79EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width, 61EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width,
diff --git a/src/common/emu_window.h b/src/common/emu_window.h
index 8e4b510e9..2be7517bc 100644
--- a/src/common/emu_window.h
+++ b/src/common/emu_window.h
@@ -78,27 +78,41 @@ public:
78 78
79 /** 79 /**
80 * Signal that a touch pressed event has occurred (e.g. mouse click pressed) 80 * Signal that a touch pressed event has occurred (e.g. mouse click pressed)
81 * @param layout FramebufferLayout object describing the framebuffer size and screen positions
82 * @param framebuffer_x Framebuffer x-coordinate that was pressed 81 * @param framebuffer_x Framebuffer x-coordinate that was pressed
83 * @param framebuffer_y Framebuffer y-coordinate that was pressed 82 * @param framebuffer_y Framebuffer y-coordinate that was pressed
84 */ 83 */
85 void TouchPressed(const FramebufferLayout& layout, unsigned framebuffer_x, unsigned framebuffer_y); 84 void TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y);
86 85
87 /** 86 /// Signal that a touch released event has occurred (e.g. mouse click released)
88 * Signal that a touch released event has occurred (e.g. mouse click released) 87 void TouchReleased();
89 * @param layout FramebufferLayout object describing the framebuffer size and screen positions
90 * @param framebuffer_x Framebuffer x-coordinate that was released
91 * @param framebuffer_y Framebuffer y-coordinate that was released
92 */
93 void TouchReleased(const FramebufferLayout& layout, unsigned framebuffer_x, unsigned framebuffer_y);
94 88
95 /** 89 /**
96 * Signal that a touch movement event has occurred (e.g. mouse was moved over the emu window) 90 * Signal that a touch movement event has occurred (e.g. mouse was moved over the emu window)
97 * @param layout FramebufferLayout object describing the framebuffer size and screen positions
98 * @param framebuffer_x Framebuffer x-coordinate 91 * @param framebuffer_x Framebuffer x-coordinate
99 * @param framebuffer_y Framebuffer y-coordinate 92 * @param framebuffer_y Framebuffer y-coordinate
100 */ 93 */
101 void TouchMoved(const FramebufferLayout& layout, unsigned framebuffer_x, unsigned framebuffer_y); 94 void TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y);
95
96 /**
97 * Gets the current pad state (which buttons are pressed and the circle pad direction).
98 * @note This should be called by the core emu thread to get a state set by the window thread.
99 * @todo Fix this function to be thread-safe.
100 * @return PadState object indicating the current pad state
101 */
102 const Service::HID::PadState GetPadState() const {
103 return pad_state;
104 }
105
106 /**
107 * Gets the current touch screen state (touch X/Y coordinates and whether or not it is pressed).
108 * @note This should be called by the core emu thread to get a state set by the window thread.
109 * @todo Fix this function to be thread-safe.
110 * @return std::tuple of (x, y, pressed) where `x` and `y` are the touch coordinates and
111 * `pressed` is true if the touch screen is currently being pressed
112 */
113 const std::tuple<u16, u16, bool>& GetTouchState() const {
114 return std::make_tuple(touch_x, touch_y, touch_pressed);
115 }
102 116
103 /** 117 /**
104 * Returns currently active configuration. 118 * Returns currently active configuration.
@@ -124,21 +138,15 @@ public:
124 return framebuffer_layout; 138 return framebuffer_layout;
125 } 139 }
126 140
127 /**
128 * Gets window client area width in logical coordinates.
129 * @note For high-DPI systems, this is smaller than the framebuffer size.
130 * @note This method is thread-safe
131 */
132 std::pair<unsigned,unsigned> GetClientAreaSize() const {
133 return std::make_pair(client_area_width, client_area_height);
134 }
135
136protected: 141protected:
137 EmuWindow() 142 EmuWindow() {
138 {
139 // TODO: Find a better place to set this. 143 // TODO: Find a better place to set this.
140 config.min_client_area_size = std::make_pair(400u, 480u); 144 config.min_client_area_size = std::make_pair(400u, 480u);
141 active_config = config; 145 active_config = config;
146 pad_state.hex = 0;
147 touch_x = 0;
148 touch_y = 0;
149 touch_pressed = false;
142 } 150 }
143 virtual ~EmuWindow() {} 151 virtual ~EmuWindow() {}
144 152
@@ -194,4 +202,9 @@ private:
194 WindowConfig active_config; ///< Internal active configuration 202 WindowConfig active_config; ///< Internal active configuration
195 203
196 bool touch_pressed; ///< True if touchpad area is currently pressed, otherwise false 204 bool touch_pressed; ///< True if touchpad area is currently pressed, otherwise false
205
206 u16 touch_x; ///< Touchpad X-position in native 3DS pixel coordinates (0-320)
207 u16 touch_y; ///< Touchpad Y-position in native 3DS pixel coordinates (0-240)
208
209 Service::HID::PadState pad_state;
197}; 210};
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
15namespace Service { 17namespace Service {
16namespace HID { 18namespace HID {
17 19
@@ -23,15 +25,8 @@ Kernel::SharedPtr<Kernel::Event> g_event_accelerometer;
23Kernel::SharedPtr<Kernel::Event> g_event_gyroscope; 25Kernel::SharedPtr<Kernel::Event> g_event_gyroscope;
24Kernel::SharedPtr<Kernel::Event> g_event_debug_pad; 26Kernel::SharedPtr<Kernel::Event> g_event_debug_pad;
25 27
26// Next Pad state update information
27static PadState next_state = {{0}};
28static u32 next_pad_index = 0; 28static u32 next_pad_index = 0;
29static s16 next_pad_circle_x = 0;
30static s16 next_pad_circle_y = 0;
31
32static u32 next_touch_index = 0; 29static u32 next_touch_index = 0;
33static u16 next_touch_x = 0;
34static 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/** 53void 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 */
65static 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
73void PadButtonPress(const PadState& pad_state) {
74 next_state.hex |= pad_state.hex;
75 UpdateNextCirclePadState();
76}
77
78void PadButtonRelease(const PadState& pad_state) {
79 next_state.hex &= ~pad_state.hex;
80 UpdateNextCirclePadState();
81}
82
83void 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
132void TouchPress(u16 x, u16 y) {
133 next_touch_x = x;
134 next_touch_y = y;
135}
136
137void TouchRelease() {
138 next_touch_x = 0;
139 next_touch_y = 0;
140}
141
142void 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
205void HIDShutdown() { 147void 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 */
177void GetIPCHandles(Interface* self); 177void GetIPCHandles(Interface* self);
178 178
179/** 179/// Checks for user input updates
180 * Sets a Pad state (button or button combo) as pressed 180void HIDUpdate();
181 * @param pad_state PadState data indicating which buttons have been pressed
182 */
183void 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 */
189void 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 */
195void 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 */
202void TouchPress(u16 x, u16 y);
203
204/// Signal that touchpad has been released
205void TouchRelease();
206
207/// Signal that touchpad updates have been completed
208void TouchUpdateComplete();
209 181
182/// Initialize HID service
210void HIDInit(); 183void HIDInit();
184
185/// Shutdown HID service
211void HIDShutdown(); 186void 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}