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.1.1.1 by cebix, 1999-10-03T14:16:25Z vs.
Revision 1.8 by cebix, 2002-01-15T14:58:32Z

# 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-2002 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 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 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 +        SetInterruptFlag(INTFLAG_ADB);
235 +        TriggerInterrupt();
236   }
237  
238  
# Line 212 | 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 231 | 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 247 | 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 262 | 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 279 | 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;
339  
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]) {
290 <                        uint32 mouse_base = adb_base + 16;
291 <                        uint8 *mouse_data = Mac2HostAddr(tmp_data);
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 <                                mouse_data[0] = 3;
349 <                                mouse_data[1] = (my & 0x7f) | (mouse_button[0] ? 0 : 0x80);
350 <                                mouse_data[2] = (mx & 0x7f) | (mouse_button[1] ? 0 : 0x80);
351 <                                mouse_data[3] = ((my >> 3) & 0x70) | ((mx >> 7) & 0x07) | (mouse_button[2] ? 0x08 : 0x88);
348 >                                WriteMacInt8(tmp_data, 3);
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 <                                mouse_data[0] = 2;
355 <                                mouse_data[1] = (my & 0x7f) | (mouse_button[0] ? 0 : 0x80);
356 <                                mouse_data[2] = (mx & 0x7f) | (mouse_button[1] ? 0 : 0x80);
354 >                                WriteMacInt8(tmp_data, 2);
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 310 | 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];
316 <                        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 {
371  
372                  // Update mouse position (absolute)
373                  if (mx != old_mouse_x || my != old_mouse_y) {
374 + #ifdef POWERPC_ROM
375 +                        static const uint16 proc[] = {
376 +                                0x2f08,         // move.l a0,-(sp)
377 +                                0x2f00,         // move.l d0,-(sp)
378 +                                0x2f01,         // move.l d1,-(sp)
379 +                                0x7001,         // moveq #1,d0 (MoveTo)
380 +                                0xaadb,         // CursorDeviceDispatch
381 +                                M68K_RTS
382 +                        };
383 +                        r.a[0] = ReadMacInt32(mouse_base + 4);
384 +                        r.d[0] = mx;
385 +                        r.d[1] = my;
386 +                        Execute68k((uint32)proc, &r);
387 + #else
388                          WriteMacInt16(0x82a, mx);
389                          WriteMacInt16(0x828, my);
390                          WriteMacInt16(0x82e, mx);
391                          WriteMacInt16(0x82c, my);
392                          WriteMacInt8(0x8ce, ReadMacInt8(0x8cf));        // CrsrCouple -> CrsrNew
393 + #endif
394                          old_mouse_x = mx;
395                          old_mouse_y = my;
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;
335                        uint8 *mouse_data = Mac2HostAddr(tmp_data);
401  
402                          // Call mouse ADB handler
403                          if (mouse_reg_3[1] == 4) {
404                                  // Extended mouse protocol
405 <                                mouse_data[0] = 3;
406 <                                mouse_data[1] = mouse_button[0] ? 0 : 0x80;
407 <                                mouse_data[2] = mouse_button[1] ? 0 : 0x80;
408 <                                mouse_data[3] = mouse_button[2] ? 0x08 : 0x88;
405 >                                WriteMacInt8(tmp_data, 3);
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 <                                mouse_data[0] = 2;
412 <                                mouse_data[1] = mouse_button[0] ? 0 : 0x80;
413 <                                mouse_data[2] = mouse_button[1] ? 0 : 0x80;
411 >                                WriteMacInt8(tmp_data, 2);
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 354 | 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  
428          // Process accumulated keyboard events
364        uint32 key_base = adb_base + 4;
365        uint8 *key_data = Mac2HostAddr(tmp_data);
429          while (key_read_ptr != key_write_ptr) {
430  
431                  // Read keyboard event
# Line 370 | Line 433 | void ADBInterrupt(void)
433                  key_read_ptr = (key_read_ptr + 1) % KEY_BUFFER_SIZE;
434  
435                  // Call keyboard ADB handler
436 <                key_data[0] = 2;
437 <                key_data[1] = mac_code;
438 <                key_data[2] = mac_code == 0x7f ? 0x7f : 0xff;   // Power key is special
436 >                WriteMacInt8(tmp_data, 2);
437 >                WriteMacInt8(tmp_data + 1, mac_code);
438 >                WriteMacInt8(tmp_data + 2, mac_code == 0x7f ? 0x7f : 0xff);     // Power key is special
439                  r.a[0] = tmp_data;
440                  r.a[1] = ReadMacInt32(key_base);
441                  r.a[2] = ReadMacInt32(key_base + 4);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines