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.11 by gbeauche, 2004-01-10T08:54:14Z

# 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 28 | Line 28
28  
29   #include "sysdeps.h"
30   #include "cpu_emulation.h"
31 + #include "emul_op.h"
32   #include "main.h"
33 + #include "prefs.h"
34   #include "video.h"
35   #include "adb.h"
36  
# Line 56 | Line 58 | static uint8 mouse_reg_3[2] = {0x63, 0x0
58   static uint8 key_reg_2[2] = {0xff, 0xff};       // Keyboard ADB register 2
59   static uint8 key_reg_3[2] = {0x62, 0x05};       // Keyboard ADB register 3
60  
61 + static uint8 m_keyboard_type = 0x05;
62 +
63 + // ADB mouse motion lock (for platforms that use separate input thread)
64 + static B2_mutex *mouse_lock;
65 +
66 +
67 + /*
68 + *  Initialize ADB emulation
69 + */
70 +
71 + void ADBInit(void)
72 + {
73 +        mouse_lock = B2_create_mutex();
74 +        m_keyboard_type = (uint8)PrefsFindInt32("keyboardtype");
75 +        key_reg_3[1] = m_keyboard_type;
76 + }
77 +
78 +
79 + /*
80 + *  Exit ADB emulation
81 + */
82 +
83 + void ADBExit(void)
84 + {
85 +        if (mouse_lock) {
86 +                B2_delete_mutex(mouse_lock);
87 +                mouse_lock = NULL;
88 +        }
89 + }
90 +
91  
92   /*
93   *  ADBOp() replacement
# Line 72 | Line 104 | void ADBOp(uint8 op, uint8 *data)
104                  key_reg_2[0] = 0xff;
105                  key_reg_2[1] = 0xff;
106                  key_reg_3[0] = 0x62;
107 <                key_reg_3[1] = 0x05;
107 >                key_reg_3[1] = m_keyboard_type;
108                  return;
109          }
110  
# Line 192 | Line 224 | void ADBOp(uint8 op, uint8 *data)
224  
225  
226   /*
227 < *  Mouse was moved (x/y are absolute or relative, depending on ADBSetMouseMode())
227 > *  Mouse was moved (x/y are absolute or relative, depending on ADBSetRelMouseMode())
228   */
229  
230   void ADBMouseMoved(int x, int y)
231   {
232 +        B2_lock_mutex(mouse_lock);
233          if (relative_mouse) {
234                  mouse_x += x; mouse_y += y;
235          } else {
236                  mouse_x = x; mouse_y = y;
237          }
238 +        B2_unlock_mutex(mouse_lock);
239 +        SetInterruptFlag(INTFLAG_ADB);
240 +        TriggerInterrupt();
241   }
242  
243  
# Line 212 | Line 248 | void ADBMouseMoved(int x, int y)
248   void ADBMouseDown(int button)
249   {
250          mouse_button[button] = true;
251 +        SetInterruptFlag(INTFLAG_ADB);
252 +        TriggerInterrupt();
253   }
254  
255  
256   /*
257 < *  First mouse button released
257 > *  Mouse button released
258   */
259  
260   void ADBMouseUp(int button)
261   {
262          mouse_button[button] = false;
263 +        SetInterruptFlag(INTFLAG_ADB);
264 +        TriggerInterrupt();
265   }
266  
267  
# Line 231 | Line 271 | void ADBMouseUp(int button)
271  
272   void ADBSetRelMouseMode(bool relative)
273   {
274 <        relative_mouse = relative;
274 >        if (relative_mouse != relative) {
275 >                relative_mouse = relative;
276 >                mouse_x = mouse_y = 0;
277 >        }
278   }
279  
280  
# Line 247 | Line 290 | void ADBKeyDown(int code)
290  
291          // Set key in matrix
292          key_states[code >> 3] |= (1 << (~code & 7));
293 +
294 +        // Trigger interrupt
295 +        SetInterruptFlag(INTFLAG_ADB);
296 +        TriggerInterrupt();
297   }
298  
299  
# Line 262 | Line 309 | void ADBKeyUp(int code)
309  
310          // Clear key in matrix
311          key_states[code >> 3] &= ~(1 << (~code & 7));
312 +
313 +        // Trigger interrupt
314 +        SetInterruptFlag(INTFLAG_ADB);
315 +        TriggerInterrupt();
316   }
317  
318  
# Line 279 | Line 330 | void ADBInterrupt(void)
330                  return;
331          uint32 tmp_data = adb_base + 0x163;     // Temporary storage for faked ADB data
332  
333 <        // Get position so that it won't change during processing
333 >        // Get mouse state
334 >        B2_lock_mutex(mouse_lock);
335          int mx = mouse_x;
336          int my = mouse_y;
337 +        if (relative_mouse)
338 +                mouse_x = mouse_y = 0;
339 +        int mb[3] = {mouse_button[0], mouse_button[1], mouse_button[2]};
340 +        B2_unlock_mutex(mouse_lock);
341 +
342 +        uint32 key_base = adb_base + 4;
343 +        uint32 mouse_base = adb_base + 16;
344  
345          if (relative_mouse) {
346  
347                  // Mouse movement (relative) and buttons
348 <                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);
348 >                if (mx != 0 || my != 0 || mb[0] != old_mouse_button[0] || mb[1] != old_mouse_button[1] || mb[2] != old_mouse_button[2]) {
349  
350                          // Call mouse ADB handler
351                          if (mouse_reg_3[1] == 4) {
352                                  // Extended mouse protocol
353 <                                mouse_data[0] = 3;
354 <                                mouse_data[1] = (my & 0x7f) | (mouse_button[0] ? 0 : 0x80);
355 <                                mouse_data[2] = (mx & 0x7f) | (mouse_button[1] ? 0 : 0x80);
356 <                                mouse_data[3] = ((my >> 3) & 0x70) | ((mx >> 7) & 0x07) | (mouse_button[2] ? 0x08 : 0x88);
353 >                                WriteMacInt8(tmp_data, 3);
354 >                                WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mb[0] ? 0 : 0x80));
355 >                                WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mb[1] ? 0 : 0x80));
356 >                                WriteMacInt8(tmp_data + 3, ((my >> 3) & 0x70) | ((mx >> 7) & 0x07) | (mb[2] ? 0x08 : 0x88));
357                          } else {
358                                  // 100/200 dpi mode
359 <                                mouse_data[0] = 2;
360 <                                mouse_data[1] = (my & 0x7f) | (mouse_button[0] ? 0 : 0x80);
361 <                                mouse_data[2] = (mx & 0x7f) | (mouse_button[1] ? 0 : 0x80);
359 >                                WriteMacInt8(tmp_data, 2);
360 >                                WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mb[0] ? 0 : 0x80));
361 >                                WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mb[1] ? 0 : 0x80));
362                          }      
363                          r.a[0] = tmp_data;
364                          r.a[1] = ReadMacInt32(mouse_base);
# Line 310 | Line 367 | void ADBInterrupt(void)
367                          r.d[0] = (mouse_reg_3[0] << 4) | 0x0c;  // Talk 0
368                          Execute68k(r.a[1], &r);
369  
370 <                        mouse_x = mouse_y = 0;
371 <                        old_mouse_button[0] = mouse_button[0];
372 <                        old_mouse_button[1] = mouse_button[1];
316 <                        old_mouse_button[2] = mouse_button[2];
370 >                        old_mouse_button[0] = mb[0];
371 >                        old_mouse_button[1] = mb[1];
372 >                        old_mouse_button[2] = mb[2];
373                  }
374  
375          } else {
376  
377                  // Update mouse position (absolute)
378                  if (mx != old_mouse_x || my != old_mouse_y) {
379 + #ifdef POWERPC_ROM
380 +                        static const uint16 proc[] = {
381 +                                PW(0x2f08),             // move.l a0,-(sp)
382 +                                PW(0x2f00),             // move.l d0,-(sp)
383 +                                PW(0x2f01),             // move.l d1,-(sp)
384 +                                PW(0x7001),             // moveq #1,d0 (MoveTo)
385 +                                PW(0xaadb),             // CursorDeviceDispatch
386 +                                PW(M68K_RTS)
387 +                        };
388 +                        r.a[0] = ReadMacInt32(mouse_base + 4);
389 +                        r.d[0] = mx;
390 +                        r.d[1] = my;
391 +                        Execute68k((uint32)proc, &r);
392 + #else
393                          WriteMacInt16(0x82a, mx);
394                          WriteMacInt16(0x828, my);
395                          WriteMacInt16(0x82e, mx);
396                          WriteMacInt16(0x82c, my);
397                          WriteMacInt8(0x8ce, ReadMacInt8(0x8cf));        // CrsrCouple -> CrsrNew
398 + #endif
399                          old_mouse_x = mx;
400                          old_mouse_y = my;
401                  }
402  
403                  // Send mouse button events
404 <                if (mouse_button[0] != old_mouse_button[0]) {
404 >                if (mb[0] != old_mouse_button[0] || mb[1] != old_mouse_button[1] || mb[2] != old_mouse_button[2]) {
405                          uint32 mouse_base = adb_base + 16;
335                        uint8 *mouse_data = Mac2HostAddr(tmp_data);
406  
407                          // Call mouse ADB handler
408                          if (mouse_reg_3[1] == 4) {
409                                  // Extended mouse protocol
410 <                                mouse_data[0] = 3;
411 <                                mouse_data[1] = mouse_button[0] ? 0 : 0x80;
412 <                                mouse_data[2] = mouse_button[1] ? 0 : 0x80;
413 <                                mouse_data[3] = mouse_button[2] ? 0x08 : 0x88;
410 >                                WriteMacInt8(tmp_data, 3);
411 >                                WriteMacInt8(tmp_data + 1, mb[0] ? 0 : 0x80);
412 >                                WriteMacInt8(tmp_data + 2, mb[1] ? 0 : 0x80);
413 >                                WriteMacInt8(tmp_data + 3, mb[2] ? 0x08 : 0x88);
414                          } else {
415                                  // 100/200 dpi mode
416 <                                mouse_data[0] = 2;
417 <                                mouse_data[1] = mouse_button[0] ? 0 : 0x80;
418 <                                mouse_data[2] = mouse_button[1] ? 0 : 0x80;
416 >                                WriteMacInt8(tmp_data, 2);
417 >                                WriteMacInt8(tmp_data + 1, mb[0] ? 0 : 0x80);
418 >                                WriteMacInt8(tmp_data + 2, mb[1] ? 0 : 0x80);
419                          }
420                          r.a[0] = tmp_data;
421                          r.a[1] = ReadMacInt32(mouse_base);
# Line 354 | Line 424 | void ADBInterrupt(void)
424                          r.d[0] = (mouse_reg_3[0] << 4) | 0x0c;  // Talk 0
425                          Execute68k(r.a[1], &r);
426  
427 <                        old_mouse_button[0] = mouse_button[0];
428 <                        old_mouse_button[1] = mouse_button[1];
429 <                        old_mouse_button[2] = mouse_button[2];
427 >                        old_mouse_button[0] = mb[0];
428 >                        old_mouse_button[1] = mb[1];
429 >                        old_mouse_button[2] = mb[2];
430                  }
431          }
432  
433          // Process accumulated keyboard events
364        uint32 key_base = adb_base + 4;
365        uint8 *key_data = Mac2HostAddr(tmp_data);
434          while (key_read_ptr != key_write_ptr) {
435  
436                  // Read keyboard event
# Line 370 | Line 438 | void ADBInterrupt(void)
438                  key_read_ptr = (key_read_ptr + 1) % KEY_BUFFER_SIZE;
439  
440                  // Call keyboard ADB handler
441 <                key_data[0] = 2;
442 <                key_data[1] = mac_code;
443 <                key_data[2] = mac_code == 0x7f ? 0x7f : 0xff;   // Power key is special
441 >                WriteMacInt8(tmp_data, 2);
442 >                WriteMacInt8(tmp_data + 1, mac_code);
443 >                WriteMacInt8(tmp_data + 2, mac_code == 0x7f ? 0x7f : 0xff);     // Power key is special
444                  r.a[0] = tmp_data;
445                  r.a[1] = ReadMacInt32(key_base);
446                  r.a[2] = ReadMacInt32(key_base + 4);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines