summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar bunnei2015-03-08 03:05:56 -0400
committerGravatar bunnei2015-03-10 18:05:17 -0400
commit1a904ded40c87c41c404cfe5e74722c0a6554926 (patch)
tree3691ced6a6cc6b5451df361392c1d079b80430df /src/core
parentHID: Moved some docstrings to the header. (diff)
downloadyuzu-1a904ded40c87c41c404cfe5e74722c0a6554926.tar.gz
yuzu-1a904ded40c87c41c404cfe5e74722c0a6554926.tar.xz
yuzu-1a904ded40c87c41c404cfe5e74722c0a6554926.zip
HID: Added functions to emulate the touchpad.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hle/service/hid/hid.cpp48
-rw-r--r--src/core/hle/service/hid/hid.h13
2 files changed, 61 insertions, 0 deletions
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index 5812724d2..29213e0fe 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -29,6 +29,10 @@ static u32 next_pad_index = 0;
29static s16 next_pad_circle_x = 0; 29static s16 next_pad_circle_x = 0;
30static s16 next_pad_circle_y = 0; 30static s16 next_pad_circle_y = 0;
31 31
32static u32 next_touch_index = 0;
33static u16 next_touch_x = 0;
34static u16 next_touch_y = 0;
35
32/** 36/**
33 * Gets a pointer to the PadData structure inside HID shared memory 37 * Gets a pointer to the PadData structure inside HID shared memory
34 */ 38 */
@@ -125,6 +129,50 @@ void PadUpdateComplete() {
125 g_event_pad_or_touch_2->Signal(); 129 g_event_pad_or_touch_2->Signal();
126} 130}
127 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;
149 next_touch_index = (next_touch_index + 1) % shared_mem->touch.entries.size();
150
151 // Get the current touch entry
152 TouchDataEntry* current_touch_entry = &shared_mem->touch.entries[shared_mem->touch.index];
153
154 // Set touchpad position
155 current_touch_entry->x = next_touch_x;
156 current_touch_entry->y = next_touch_y;
157
158 // TODO(bunnei): Verify this behavior on real hardware
159 current_touch_entry->data_valid = (next_touch_x || next_touch_y) ? 1 : 0;
160
161 // 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
163 // converted to pixel coordinates." (http://3dbrew.org/wiki/HID_Shared_Memory#Offset_0xA8).
164
165 // If we just updated index 0, provide a new timestamp
166 if (shared_mem->touch.index == 0) {
167 shared_mem->touch.index_reset_ticks_previous = shared_mem->touch.index_reset_ticks;
168 shared_mem->touch.index_reset_ticks = (s64)Core::g_app_core->GetTicks();
169 }
170
171 // Signal both handles when there's an update to Pad or touch
172 g_event_pad_or_touch_1->Signal();
173 g_event_pad_or_touch_2->Signal();
174}
175
128void GetIPCHandles(Service::Interface* self) { 176void GetIPCHandles(Service::Interface* self) {
129 u32* cmd_buff = Kernel::GetCommandBuffer(); 177 u32* cmd_buff = Kernel::GetCommandBuffer();
130 178
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h
index cd6263243..f2affb5c5 100644
--- a/src/core/hle/service/hid/hid.h
+++ b/src/core/hle/service/hid/hid.h
@@ -180,6 +180,19 @@ void PadButtonRelease(const PadState& pad_state);
180 */ 180 */
181void PadUpdateComplete(); 181void PadUpdateComplete();
182 182
183/**
184 * Signal that the touchpad has been pressed
185 * @param x Touchpad x-coordinate in bottom screen pixels (between 0 and 320)
186 * @param y Touchpad y-coordinate in bottom screen pixels (between 0 and 240)
187 */
188void TouchPress(u16 x, u16 y);
189
190/// Signal that touchpad has been released
191void TouchRelease();
192
193/// Signal that touchpad updates have been completed
194void TouchUpdateComplete();
195
183void HIDInit(); 196void HIDInit();
184void HIDShutdown(); 197void HIDShutdown();
185 198