57 |
|
static uint8 key_reg_2[2] = {0xff, 0xff}; // Keyboard ADB register 2 |
58 |
|
static uint8 key_reg_3[2] = {0x62, 0x05}; // Keyboard ADB register 3 |
59 |
|
|
60 |
+ |
// ADB mouse input state lock (for platforms that use separate input thread) |
61 |
+ |
static B2_mutex *mouse_lock; |
62 |
+ |
|
63 |
+ |
|
64 |
+ |
/* |
65 |
+ |
* Initialize ADB emulation |
66 |
+ |
*/ |
67 |
+ |
|
68 |
+ |
void ADBInit(void) |
69 |
+ |
{ |
70 |
+ |
mouse_lock = B2_create_mutex(); |
71 |
+ |
} |
72 |
+ |
|
73 |
+ |
|
74 |
+ |
/* |
75 |
+ |
* Exit ADB emulation |
76 |
+ |
*/ |
77 |
+ |
|
78 |
+ |
void ADBExit(void) |
79 |
+ |
{ |
80 |
+ |
if (mouse_lock) { |
81 |
+ |
B2_delete_mutex(mouse_lock); |
82 |
+ |
mouse_lock = NULL; |
83 |
+ |
} |
84 |
+ |
} |
85 |
+ |
|
86 |
|
|
87 |
|
/* |
88 |
|
* ADBOp() replacement |
224 |
|
|
225 |
|
void ADBMouseMoved(int x, int y) |
226 |
|
{ |
227 |
+ |
B2_lock_mutex(mouse_lock); |
228 |
|
if (relative_mouse) { |
229 |
|
mouse_x += x; mouse_y += y; |
230 |
|
} else { |
231 |
|
mouse_x = x; mouse_y = y; |
232 |
|
} |
233 |
+ |
B2_unlock_mutex(mouse_lock); |
234 |
|
} |
235 |
|
|
236 |
|
|
240 |
|
|
241 |
|
void ADBMouseDown(int button) |
242 |
|
{ |
243 |
+ |
B2_lock_mutex(mouse_lock); |
244 |
|
mouse_button[button] = true; |
245 |
+ |
B2_unlock_mutex(mouse_lock); |
246 |
|
} |
247 |
|
|
248 |
|
|
252 |
|
|
253 |
|
void ADBMouseUp(int button) |
254 |
|
{ |
255 |
+ |
B2_lock_mutex(mouse_lock); |
256 |
|
mouse_button[button] = false; |
257 |
+ |
B2_unlock_mutex(mouse_lock); |
258 |
|
} |
259 |
|
|
260 |
|
|
312 |
|
return; |
313 |
|
uint32 tmp_data = adb_base + 0x163; // Temporary storage for faked ADB data |
314 |
|
|
315 |
< |
// Get position so that it won't change during processing |
315 |
> |
// Get mouse state |
316 |
> |
B2_lock_mutex(mouse_lock); |
317 |
|
int mx = mouse_x; |
318 |
|
int my = mouse_y; |
319 |
+ |
if (relative_mouse) |
320 |
+ |
mouse_x = mouse_y = 0; |
321 |
+ |
int mb[3] = {mouse_button[0], mouse_button[1], mouse_button[2]}; |
322 |
+ |
B2_unlock_mutex(mouse_lock); |
323 |
|
|
324 |
|
uint32 key_base = adb_base + 4; |
325 |
|
uint32 mouse_base = adb_base + 16; |
327 |
|
if (relative_mouse) { |
328 |
|
|
329 |
|
// Mouse movement (relative) and buttons |
330 |
< |
if (mx != 0 || my != 0 || mouse_button[0] != old_mouse_button[0] || mouse_button[1] != old_mouse_button[1] || mouse_button[2] != old_mouse_button[2]) { |
330 |
> |
if (mx != 0 || my != 0 || mb[0] != old_mouse_button[0] || mb[1] != old_mouse_button[1] || mb[2] != old_mouse_button[2]) { |
331 |
|
|
332 |
|
// Call mouse ADB handler |
333 |
|
if (mouse_reg_3[1] == 4) { |
334 |
|
// Extended mouse protocol |
335 |
|
WriteMacInt8(tmp_data, 3); |
336 |
< |
WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mouse_button[0] ? 0 : 0x80)); |
337 |
< |
WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mouse_button[1] ? 0 : 0x80)); |
338 |
< |
WriteMacInt8(tmp_data + 3, ((my >> 3) & 0x70) | ((mx >> 7) & 0x07) | (mouse_button[2] ? 0x08 : 0x88)); |
336 |
> |
WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mb[0] ? 0 : 0x80)); |
337 |
> |
WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mb[1] ? 0 : 0x80)); |
338 |
> |
WriteMacInt8(tmp_data + 3, ((my >> 3) & 0x70) | ((mx >> 7) & 0x07) | (mb[2] ? 0x08 : 0x88)); |
339 |
|
} else { |
340 |
|
// 100/200 dpi mode |
341 |
|
WriteMacInt8(tmp_data, 2); |
342 |
< |
WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mouse_button[0] ? 0 : 0x80)); |
343 |
< |
WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mouse_button[1] ? 0 : 0x80)); |
342 |
> |
WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mb[0] ? 0 : 0x80)); |
343 |
> |
WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mb[1] ? 0 : 0x80)); |
344 |
|
} |
345 |
|
r.a[0] = tmp_data; |
346 |
|
r.a[1] = ReadMacInt32(mouse_base); |
349 |
|
r.d[0] = (mouse_reg_3[0] << 4) | 0x0c; // Talk 0 |
350 |
|
Execute68k(r.a[1], &r); |
351 |
|
|
352 |
< |
mouse_x = mouse_y = 0; |
353 |
< |
old_mouse_button[0] = mouse_button[0]; |
354 |
< |
old_mouse_button[1] = mouse_button[1]; |
318 |
< |
old_mouse_button[2] = mouse_button[2]; |
352 |
> |
old_mouse_button[0] = mb[0]; |
353 |
> |
old_mouse_button[1] = mb[1]; |
354 |
> |
old_mouse_button[2] = mb[2]; |
355 |
|
} |
356 |
|
|
357 |
|
} else { |
383 |
|
} |
384 |
|
|
385 |
|
// Send mouse button events |
386 |
< |
if (mouse_button[0] != old_mouse_button[0]) { |
386 |
> |
if (mb[0] != old_mouse_button[0] || mb[1] != old_mouse_button[1] || mb[2] != old_mouse_button[2]) { |
387 |
|
uint32 mouse_base = adb_base + 16; |
388 |
|
|
389 |
|
// Call mouse ADB handler |
390 |
|
if (mouse_reg_3[1] == 4) { |
391 |
|
// Extended mouse protocol |
392 |
|
WriteMacInt8(tmp_data, 3); |
393 |
< |
WriteMacInt8(tmp_data + 1, mouse_button[0] ? 0 : 0x80); |
394 |
< |
WriteMacInt8(tmp_data + 2, mouse_button[1] ? 0 : 0x80); |
395 |
< |
WriteMacInt8(tmp_data + 3, mouse_button[2] ? 0x08 : 0x88); |
393 |
> |
WriteMacInt8(tmp_data + 1, mb[0] ? 0 : 0x80); |
394 |
> |
WriteMacInt8(tmp_data + 2, mb[1] ? 0 : 0x80); |
395 |
> |
WriteMacInt8(tmp_data + 3, mb[2] ? 0x08 : 0x88); |
396 |
|
} else { |
397 |
|
// 100/200 dpi mode |
398 |
|
WriteMacInt8(tmp_data, 2); |
399 |
< |
WriteMacInt8(tmp_data + 1, mouse_button[0] ? 0 : 0x80); |
400 |
< |
WriteMacInt8(tmp_data + 2, mouse_button[1] ? 0 : 0x80); |
399 |
> |
WriteMacInt8(tmp_data + 1, mb[0] ? 0 : 0x80); |
400 |
> |
WriteMacInt8(tmp_data + 2, mb[1] ? 0 : 0x80); |
401 |
|
} |
402 |
|
r.a[0] = tmp_data; |
403 |
|
r.a[1] = ReadMacInt32(mouse_base); |
406 |
|
r.d[0] = (mouse_reg_3[0] << 4) | 0x0c; // Talk 0 |
407 |
|
Execute68k(r.a[1], &r); |
408 |
|
|
409 |
< |
old_mouse_button[0] = mouse_button[0]; |
410 |
< |
old_mouse_button[1] = mouse_button[1]; |
411 |
< |
old_mouse_button[2] = mouse_button[2]; |
409 |
> |
old_mouse_button[0] = mb[0]; |
410 |
> |
old_mouse_button[1] = mb[1]; |
411 |
> |
old_mouse_button[2] = mb[2]; |
412 |
|
} |
413 |
|
} |
414 |
|
|