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.4 by cebix, 2000-07-25T11:13:24Z vs.
Revision 1.7 by cebix, 2001-07-09T11:21:59Z

# Line 1 | Line 1
1   /*
2   *  adb.cpp - ADB emulation (mouse/keyboard)
3   *
4 < *  Basilisk II (C) 1997-2000 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 57 | 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 motion 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 198 | Line 224 | void ADBOp(uint8 op, uint8 *data)
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 +        SetInterruptFlag(INTFLAG_ADB);
235 +        TriggerInterrupt();
236   }
237  
238  
# Line 213 | Line 243 | void ADBMouseMoved(int x, int y)
243   void ADBMouseDown(int button)
244   {
245          mouse_button[button] = true;
246 +        SetInterruptFlag(INTFLAG_ADB);
247 +        TriggerInterrupt();
248   }
249  
250  
251   /*
252 < *  First mouse button released
252 > *  Mouse button released
253   */
254  
255   void ADBMouseUp(int button)
256   {
257          mouse_button[button] = false;
258 +        SetInterruptFlag(INTFLAG_ADB);
259 +        TriggerInterrupt();
260   }
261  
262  
# Line 232 | Line 266 | void ADBMouseUp(int button)
266  
267   void ADBSetRelMouseMode(bool relative)
268   {
269 <        relative_mouse = relative;
269 >        if (relative_mouse != relative) {
270 >                relative_mouse = relative;
271 >                mouse_x = mouse_y = 0;
272 >        }
273   }
274  
275  
# Line 248 | Line 285 | void ADBKeyDown(int code)
285  
286          // Set key in matrix
287          key_states[code >> 3] |= (1 << (~code & 7));
288 +
289 +        // Trigger interrupt
290 +        SetInterruptFlag(INTFLAG_ADB);
291 +        TriggerInterrupt();
292   }
293  
294  
# Line 263 | Line 304 | void ADBKeyUp(int code)
304  
305          // Clear key in matrix
306          key_states[code >> 3] &= ~(1 << (~code & 7));
307 +
308 +        // Trigger interrupt
309 +        SetInterruptFlag(INTFLAG_ADB);
310 +        TriggerInterrupt();
311   }
312  
313  
# Line 280 | Line 325 | void ADBInterrupt(void)
325                  return;
326          uint32 tmp_data = adb_base + 0x163;     // Temporary storage for faked ADB data
327  
328 <        // Get position so that it won't change during processing
328 >        // Get mouse state
329 >        B2_lock_mutex(mouse_lock);
330          int mx = mouse_x;
331          int my = mouse_y;
332 +        if (relative_mouse)
333 +                mouse_x = mouse_y = 0;
334 +        int mb[3] = {mouse_button[0], mouse_button[1], mouse_button[2]};
335 +        B2_unlock_mutex(mouse_lock);
336  
337          uint32 key_base = adb_base + 4;
338          uint32 mouse_base = adb_base + 16;
# Line 290 | Line 340 | void ADBInterrupt(void)
340          if (relative_mouse) {
341  
342                  // Mouse movement (relative) and buttons
343 <                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]) {
343 >                if (mx != 0 || my != 0 || mb[0] != old_mouse_button[0] || mb[1] != old_mouse_button[1] || mb[2] != old_mouse_button[2]) {
344  
345                          // Call mouse ADB handler
346                          if (mouse_reg_3[1] == 4) {
347                                  // Extended mouse protocol
348                                  WriteMacInt8(tmp_data, 3);
349 <                                WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mouse_button[0] ? 0 : 0x80));
350 <                                WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mouse_button[1] ? 0 : 0x80));
351 <                                WriteMacInt8(tmp_data + 3, ((my >> 3) & 0x70) | ((mx >> 7) & 0x07) | (mouse_button[2] ? 0x08 : 0x88));
349 >                                WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mb[0] ? 0 : 0x80));
350 >                                WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mb[1] ? 0 : 0x80));
351 >                                WriteMacInt8(tmp_data + 3, ((my >> 3) & 0x70) | ((mx >> 7) & 0x07) | (mb[2] ? 0x08 : 0x88));
352                          } else {
353                                  // 100/200 dpi mode
354                                  WriteMacInt8(tmp_data, 2);
355 <                                WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mouse_button[0] ? 0 : 0x80));
356 <                                WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mouse_button[1] ? 0 : 0x80));
355 >                                WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mb[0] ? 0 : 0x80));
356 >                                WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mb[1] ? 0 : 0x80));
357                          }      
358                          r.a[0] = tmp_data;
359                          r.a[1] = ReadMacInt32(mouse_base);
# Line 312 | Line 362 | void ADBInterrupt(void)
362                          r.d[0] = (mouse_reg_3[0] << 4) | 0x0c;  // Talk 0
363                          Execute68k(r.a[1], &r);
364  
365 <                        mouse_x = mouse_y = 0;
366 <                        old_mouse_button[0] = mouse_button[0];
367 <                        old_mouse_button[1] = mouse_button[1];
318 <                        old_mouse_button[2] = mouse_button[2];
365 >                        old_mouse_button[0] = mb[0];
366 >                        old_mouse_button[1] = mb[1];
367 >                        old_mouse_button[2] = mb[2];
368                  }
369  
370          } else {
# Line 347 | Line 396 | void ADBInterrupt(void)
396                  }
397  
398                  // Send mouse button events
399 <                if (mouse_button[0] != old_mouse_button[0]) {
399 >                if (mb[0] != old_mouse_button[0] || mb[1] != old_mouse_button[1] || mb[2] != old_mouse_button[2]) {
400                          uint32 mouse_base = adb_base + 16;
401  
402                          // Call mouse ADB handler
403                          if (mouse_reg_3[1] == 4) {
404                                  // Extended mouse protocol
405                                  WriteMacInt8(tmp_data, 3);
406 <                                WriteMacInt8(tmp_data + 1, mouse_button[0] ? 0 : 0x80);
407 <                                WriteMacInt8(tmp_data + 2, mouse_button[1] ? 0 : 0x80);
408 <                                WriteMacInt8(tmp_data + 3, mouse_button[2] ? 0x08 : 0x88);
406 >                                WriteMacInt8(tmp_data + 1, mb[0] ? 0 : 0x80);
407 >                                WriteMacInt8(tmp_data + 2, mb[1] ? 0 : 0x80);
408 >                                WriteMacInt8(tmp_data + 3, mb[2] ? 0x08 : 0x88);
409                          } else {
410                                  // 100/200 dpi mode
411                                  WriteMacInt8(tmp_data, 2);
412 <                                WriteMacInt8(tmp_data + 1, mouse_button[0] ? 0 : 0x80);
413 <                                WriteMacInt8(tmp_data + 2, mouse_button[1] ? 0 : 0x80);
412 >                                WriteMacInt8(tmp_data + 1, mb[0] ? 0 : 0x80);
413 >                                WriteMacInt8(tmp_data + 2, mb[1] ? 0 : 0x80);
414                          }
415                          r.a[0] = tmp_data;
416                          r.a[1] = ReadMacInt32(mouse_base);
# Line 370 | Line 419 | void ADBInterrupt(void)
419                          r.d[0] = (mouse_reg_3[0] << 4) | 0x0c;  // Talk 0
420                          Execute68k(r.a[1], &r);
421  
422 <                        old_mouse_button[0] = mouse_button[0];
423 <                        old_mouse_button[1] = mouse_button[1];
424 <                        old_mouse_button[2] = mouse_button[2];
422 >                        old_mouse_button[0] = mb[0];
423 >                        old_mouse_button[1] = mb[1];
424 >                        old_mouse_button[2] = mb[2];
425                  }
426          }
427  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines