1 |
|
/* |
2 |
|
* adb.cpp - ADB emulation (mouse/keyboard) |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-1999 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2001 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
29 |
|
#include "sysdeps.h" |
30 |
|
#include "cpu_emulation.h" |
31 |
|
#include "main.h" |
32 |
+ |
#include "emul_op.h" |
33 |
|
#include "video.h" |
34 |
|
#include "adb.h" |
35 |
|
|
193 |
|
|
194 |
|
|
195 |
|
/* |
196 |
< |
* Mouse was moved (x/y are absolute or relative, depending on ADBSetMouseMode()) |
196 |
> |
* Mouse was moved (x/y are absolute or relative, depending on ADBSetRelMouseMode()) |
197 |
|
*/ |
198 |
|
|
199 |
|
void ADBMouseMoved(int x, int y) |
284 |
|
int mx = mouse_x; |
285 |
|
int my = mouse_y; |
286 |
|
|
287 |
+ |
uint32 key_base = adb_base + 4; |
288 |
+ |
uint32 mouse_base = adb_base + 16; |
289 |
+ |
|
290 |
|
if (relative_mouse) { |
291 |
|
|
292 |
|
// Mouse movement (relative) and buttons |
293 |
|
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]) { |
290 |
– |
uint32 mouse_base = adb_base + 16; |
291 |
– |
uint8 *mouse_data = Mac2HostAddr(tmp_data); |
294 |
|
|
295 |
|
// Call mouse ADB handler |
296 |
|
if (mouse_reg_3[1] == 4) { |
297 |
|
// Extended mouse protocol |
298 |
< |
mouse_data[0] = 3; |
299 |
< |
mouse_data[1] = (my & 0x7f) | (mouse_button[0] ? 0 : 0x80); |
300 |
< |
mouse_data[2] = (mx & 0x7f) | (mouse_button[1] ? 0 : 0x80); |
301 |
< |
mouse_data[3] = ((my >> 3) & 0x70) | ((mx >> 7) & 0x07) | (mouse_button[2] ? 0x08 : 0x88); |
298 |
> |
WriteMacInt8(tmp_data, 3); |
299 |
> |
WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mouse_button[0] ? 0 : 0x80)); |
300 |
> |
WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mouse_button[1] ? 0 : 0x80)); |
301 |
> |
WriteMacInt8(tmp_data + 3, ((my >> 3) & 0x70) | ((mx >> 7) & 0x07) | (mouse_button[2] ? 0x08 : 0x88)); |
302 |
|
} else { |
303 |
|
// 100/200 dpi mode |
304 |
< |
mouse_data[0] = 2; |
305 |
< |
mouse_data[1] = (my & 0x7f) | (mouse_button[0] ? 0 : 0x80); |
306 |
< |
mouse_data[2] = (mx & 0x7f) | (mouse_button[1] ? 0 : 0x80); |
304 |
> |
WriteMacInt8(tmp_data, 2); |
305 |
> |
WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mouse_button[0] ? 0 : 0x80)); |
306 |
> |
WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mouse_button[1] ? 0 : 0x80)); |
307 |
|
} |
308 |
|
r.a[0] = tmp_data; |
309 |
|
r.a[1] = ReadMacInt32(mouse_base); |
322 |
|
|
323 |
|
// Update mouse position (absolute) |
324 |
|
if (mx != old_mouse_x || my != old_mouse_y) { |
325 |
+ |
#ifdef POWERPC_ROM |
326 |
+ |
static const uint16 proc[] = { |
327 |
+ |
0x2f08, // move.l a0,-(sp) |
328 |
+ |
0x2f00, // move.l d0,-(sp) |
329 |
+ |
0x2f01, // move.l d1,-(sp) |
330 |
+ |
0x7001, // moveq #1,d0 (MoveTo) |
331 |
+ |
0xaadb, // CursorDeviceDispatch |
332 |
+ |
M68K_RTS |
333 |
+ |
}; |
334 |
+ |
r.a[0] = ReadMacInt32(mouse_base + 4); |
335 |
+ |
r.d[0] = mx; |
336 |
+ |
r.d[1] = my; |
337 |
+ |
Execute68k((uint32)proc, &r); |
338 |
+ |
#else |
339 |
|
WriteMacInt16(0x82a, mx); |
340 |
|
WriteMacInt16(0x828, my); |
341 |
|
WriteMacInt16(0x82e, mx); |
342 |
|
WriteMacInt16(0x82c, my); |
343 |
|
WriteMacInt8(0x8ce, ReadMacInt8(0x8cf)); // CrsrCouple -> CrsrNew |
344 |
+ |
#endif |
345 |
|
old_mouse_x = mx; |
346 |
|
old_mouse_y = my; |
347 |
|
} |
349 |
|
// Send mouse button events |
350 |
|
if (mouse_button[0] != old_mouse_button[0]) { |
351 |
|
uint32 mouse_base = adb_base + 16; |
335 |
– |
uint8 *mouse_data = Mac2HostAddr(tmp_data); |
352 |
|
|
353 |
|
// Call mouse ADB handler |
354 |
|
if (mouse_reg_3[1] == 4) { |
355 |
|
// Extended mouse protocol |
356 |
< |
mouse_data[0] = 3; |
357 |
< |
mouse_data[1] = mouse_button[0] ? 0 : 0x80; |
358 |
< |
mouse_data[2] = mouse_button[1] ? 0 : 0x80; |
359 |
< |
mouse_data[3] = mouse_button[2] ? 0x08 : 0x88; |
356 |
> |
WriteMacInt8(tmp_data, 3); |
357 |
> |
WriteMacInt8(tmp_data + 1, mouse_button[0] ? 0 : 0x80); |
358 |
> |
WriteMacInt8(tmp_data + 2, mouse_button[1] ? 0 : 0x80); |
359 |
> |
WriteMacInt8(tmp_data + 3, mouse_button[2] ? 0x08 : 0x88); |
360 |
|
} else { |
361 |
|
// 100/200 dpi mode |
362 |
< |
mouse_data[0] = 2; |
363 |
< |
mouse_data[1] = mouse_button[0] ? 0 : 0x80; |
364 |
< |
mouse_data[2] = mouse_button[1] ? 0 : 0x80; |
362 |
> |
WriteMacInt8(tmp_data, 2); |
363 |
> |
WriteMacInt8(tmp_data + 1, mouse_button[0] ? 0 : 0x80); |
364 |
> |
WriteMacInt8(tmp_data + 2, mouse_button[1] ? 0 : 0x80); |
365 |
|
} |
366 |
|
r.a[0] = tmp_data; |
367 |
|
r.a[1] = ReadMacInt32(mouse_base); |
377 |
|
} |
378 |
|
|
379 |
|
// Process accumulated keyboard events |
364 |
– |
uint32 key_base = adb_base + 4; |
365 |
– |
uint8 *key_data = Mac2HostAddr(tmp_data); |
380 |
|
while (key_read_ptr != key_write_ptr) { |
381 |
|
|
382 |
|
// Read keyboard event |
384 |
|
key_read_ptr = (key_read_ptr + 1) % KEY_BUFFER_SIZE; |
385 |
|
|
386 |
|
// Call keyboard ADB handler |
387 |
< |
key_data[0] = 2; |
388 |
< |
key_data[1] = mac_code; |
389 |
< |
key_data[2] = mac_code == 0x7f ? 0x7f : 0xff; // Power key is special |
387 |
> |
WriteMacInt8(tmp_data, 2); |
388 |
> |
WriteMacInt8(tmp_data + 1, mac_code); |
389 |
> |
WriteMacInt8(tmp_data + 2, mac_code == 0x7f ? 0x7f : 0xff); // Power key is special |
390 |
|
r.a[0] = tmp_data; |
391 |
|
r.a[1] = ReadMacInt32(key_base); |
392 |
|
r.a[2] = ReadMacInt32(key_base + 4); |