ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/adb.cpp
(Generate patch)

Comparing BasiliskII/src/adb.cpp (file contents):
Revision 1.2 by cebix, 1999-11-03T10:56:10Z vs.
Revision 1.6 by cebix, 2001-07-03T15:59:45Z

# Line 1 | Line 1
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
# Line 29 | Line 29
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  
# Line 56 | Line 57 | static uint8 mouse_reg_3[2] = {0x63, 0x0
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
# Line 192 | Line 219 | void ADBOp(uint8 op, uint8 *data)
219  
220  
221   /*
222 < *  Mouse was moved (x/y are absolute or relative, depending on ADBSetMouseMode())
222 > *  Mouse was moved (x/y are absolute or relative, depending on ADBSetRelMouseMode())
223   */
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  
# Line 211 | Line 240 | void ADBMouseMoved(int x, int y)
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  
# Line 221 | Line 252 | void ADBMouseDown(int button)
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  
# Line 279 | Line 312 | void ADBInterrupt(void)
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;
326  
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]) {
290 <                        uint32 mouse_base = adb_base + 16;
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);
# Line 309 | Line 349 | void ADBInterrupt(void)
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];
315 <                        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 {
358  
359                  // Update mouse position (absolute)
360                  if (mx != old_mouse_x || my != old_mouse_y) {
361 + #ifdef POWERPC_ROM
362 +                        static const uint16 proc[] = {
363 +                                0x2f08,         // move.l a0,-(sp)
364 +                                0x2f00,         // move.l d0,-(sp)
365 +                                0x2f01,         // move.l d1,-(sp)
366 +                                0x7001,         // moveq #1,d0 (MoveTo)
367 +                                0xaadb,         // CursorDeviceDispatch
368 +                                M68K_RTS
369 +                        };
370 +                        r.a[0] = ReadMacInt32(mouse_base + 4);
371 +                        r.d[0] = mx;
372 +                        r.d[1] = my;
373 +                        Execute68k((uint32)proc, &r);
374 + #else
375                          WriteMacInt16(0x82a, mx);
376                          WriteMacInt16(0x828, my);
377                          WriteMacInt16(0x82e, mx);
378                          WriteMacInt16(0x82c, my);
379                          WriteMacInt8(0x8ce, ReadMacInt8(0x8cf));        // CrsrCouple -> CrsrNew
380 + #endif
381                          old_mouse_x = mx;
382                          old_mouse_y = my;
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);
# Line 352 | Line 406 | void ADBInterrupt(void)
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  
415          // Process accumulated keyboard events
362        uint32 key_base = adb_base + 4;
416          while (key_read_ptr != key_write_ptr) {
417  
418                  // Read keyboard event

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines