From bb691458619afb09e80e6a4f2da23796d9cb2c29 Mon Sep 17 00:00:00 2001 From: Andrew Tonner Date: Thu, 6 Feb 2020 18:12:23 -0800 Subject: [PATCH 1/2] OulanB's adb button buffer proposed change --- BasiliskII/src/adb.cpp | 99 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 91 insertions(+), 8 deletions(-) diff --git a/BasiliskII/src/adb.cpp b/BasiliskII/src/adb.cpp index c05c0000..5ab2b5b3 100644 --- a/BasiliskII/src/adb.cpp +++ b/BasiliskII/src/adb.cpp @@ -57,6 +57,11 @@ const int KEY_BUFFER_SIZE = 16; static uint8 key_buffer[KEY_BUFFER_SIZE]; static unsigned int key_read_ptr = 0, key_write_ptr = 0; +// O2S: Button event buffer (Mac button with up/down flag) -> avoid to loose tap on a trackpad +const int BUTTON_BUFFER_SIZE = 32; +static uint8 button_buffer[BUTTON_BUFFER_SIZE]; +static unsigned int button_read_ptr = 0, button_write_ptr = 0; + static uint8 mouse_reg_3[2] = {0x63, 0x01}; // Mouse ADB register 3 static uint8 key_reg_2[2] = {0xff, 0xff}; // Keyboard ADB register 2 @@ -245,13 +250,17 @@ void ADBMouseMoved(int x, int y) } -/* +/* * Mouse button pressed */ void ADBMouseDown(int button) { - mouse_button[button] = true; + // O2S: Add button to buffer + button_buffer[button_write_ptr] = button; + button_write_ptr = (button_write_ptr + 1) % BUTTON_BUFFER_SIZE; + + // O2S: mouse_button[button] = true; SetInterruptFlag(INTFLAG_ADB); TriggerInterrupt(); } @@ -263,7 +272,11 @@ void ADBMouseDown(int button) void ADBMouseUp(int button) { - mouse_button[button] = false; + // O2S: Add button to buffer + button_buffer[button_write_ptr] = button | 0x80; + button_write_ptr = (button_write_ptr + 1) % BUTTON_BUFFER_SIZE; + + // O2S: mouse_button[button] = false; SetInterruptFlag(INTFLAG_ADB); TriggerInterrupt(); } @@ -278,7 +291,7 @@ void ADBSetRelMouseMode(bool relative) if (relative_mouse != relative) { relative_mouse = relative; mouse_x = mouse_y = 0; - } + } } @@ -347,7 +360,40 @@ void ADBInterrupt(void) uint32 mouse_base = adb_base + 16; if (relative_mouse) { + while (mx != 0 || my != 0 || button_read_ptr != button_write_ptr) { + if (button_read_ptr != button_write_ptr) { + // Read button event + uint8 button = button_buffer[button_read_ptr]; + button_read_ptr = (button_read_ptr + 1) % BUTTON_BUFFER_SIZE; + mouse_button[button & 0x3] = (button & 0x80) ? false : true; + } + // Call mouse ADB handler + if (mouse_reg_3[1] == 4) { + // Extended mouse protocol + WriteMacInt8(tmp_data, 3); + WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mouse_button[0] ? 0 : 0x80)); + WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mouse_button[1] ? 0 : 0x80)); + WriteMacInt8(tmp_data + 3, ((my >> 3) & 0x70) | ((mx >> 7) & 0x07) | (mouse_button[2] ? 0x08 : 0x88)); + } else { + // 100/200 dpi mode + WriteMacInt8(tmp_data, 2); + WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mouse_button[0] ? 0 : 0x80)); + WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mouse_button[1] ? 0 : 0x80)); + } + r.a[0] = tmp_data; + r.a[1] = ReadMacInt32(mouse_base); + r.a[2] = ReadMacInt32(mouse_base + 4); + r.a[3] = adb_base; + r.d[0] = (mouse_reg_3[0] << 4) | 0x0c; // Talk 0 + Execute68k(r.a[1], &r); + old_mouse_button[0] = mouse_button[0]; + old_mouse_button[1] = mouse_button[1]; + old_mouse_button[2] = mouse_button[2]; + mx = 0; + my = 0; + } +/* O2S // Mouse movement (relative) and buttons if (mx != 0 || my != 0 || mb[0] != old_mouse_button[0] || mb[1] != old_mouse_button[1] || mb[2] != old_mouse_button[2]) { @@ -363,7 +409,7 @@ void ADBInterrupt(void) WriteMacInt8(tmp_data, 2); WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mb[0] ? 0 : 0x80)); WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mb[1] ? 0 : 0x80)); - } + } r.a[0] = tmp_data; r.a[1] = ReadMacInt32(mouse_base); r.a[2] = ReadMacInt32(mouse_base + 4); @@ -375,7 +421,7 @@ void ADBInterrupt(void) old_mouse_button[1] = mb[1]; old_mouse_button[2] = mb[2]; } - +*/ } else { // Update mouse position (absolute) @@ -405,7 +451,44 @@ void ADBInterrupt(void) old_mouse_y = my; } - // Send mouse button events + // O2S: Process accumulated button events + while (button_read_ptr != button_write_ptr) { + // Read button event + uint8 button = button_buffer[button_read_ptr]; + button_read_ptr = (button_read_ptr + 1) % BUTTON_BUFFER_SIZE; + mouse_button[button & 0x3] = (button & 0x80) ? false : true; + + if (mouse_button[0] != old_mouse_button[0] || mouse_button[1] != old_mouse_button[1] || mouse_button[2] != old_mouse_button[2]) { + uint32 mouse_base = adb_base + 16; + + // Call mouse ADB handler + if (mouse_reg_3[1] == 4) { + // Extended mouse protocol + WriteMacInt8(tmp_data, 3); + WriteMacInt8(tmp_data + 1, mouse_button[0] ? 0 : 0x80); + WriteMacInt8(tmp_data + 2, mouse_button[1] ? 0 : 0x80); + WriteMacInt8(tmp_data + 3, mouse_button[2] ? 0x08 : 0x88); + } else { + // 100/200 dpi mode + WriteMacInt8(tmp_data, 2); + WriteMacInt8(tmp_data + 1, mouse_button[0] ? 0 : 0x80); + WriteMacInt8(tmp_data + 2, mouse_button[1] ? 0 : 0x80); + } + r.a[0] = tmp_data; + r.a[1] = ReadMacInt32(mouse_base); + r.a[2] = ReadMacInt32(mouse_base + 4); + r.a[3] = adb_base; + r.d[0] = (mouse_reg_3[0] << 4) | 0x0c; // Talk 0 + Execute68k(r.a[1], &r); + + old_mouse_button[0] = mouse_button[0]; + old_mouse_button[1] = mouse_button[1]; + old_mouse_button[2] = mouse_button[2]; + } + } + + +/* // Send mouse button events if (mb[0] != old_mouse_button[0] || mb[1] != old_mouse_button[1] || mb[2] != old_mouse_button[2]) { uint32 mouse_base = adb_base + 16; @@ -432,7 +515,7 @@ void ADBInterrupt(void) old_mouse_button[0] = mb[0]; old_mouse_button[1] = mb[1]; old_mouse_button[2] = mb[2]; - } + } */ } // Process accumulated keyboard events From f86b9b2abd9d1880f505302361dfaa9684bc2ab0 Mon Sep 17 00:00:00 2001 From: Andrew Tonner Date: Thu, 6 Feb 2020 18:14:16 -0800 Subject: [PATCH 2/2] Actually remove the commented-out code --- BasiliskII/src/adb.cpp | 57 ------------------------------------------ 1 file changed, 57 deletions(-) diff --git a/BasiliskII/src/adb.cpp b/BasiliskII/src/adb.cpp index 5ab2b5b3..f89c4092 100644 --- a/BasiliskII/src/adb.cpp +++ b/BasiliskII/src/adb.cpp @@ -393,35 +393,7 @@ void ADBInterrupt(void) mx = 0; my = 0; } -/* O2S - // Mouse movement (relative) and buttons - if (mx != 0 || my != 0 || mb[0] != old_mouse_button[0] || mb[1] != old_mouse_button[1] || mb[2] != old_mouse_button[2]) { - // Call mouse ADB handler - if (mouse_reg_3[1] == 4) { - // Extended mouse protocol - WriteMacInt8(tmp_data, 3); - WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mb[0] ? 0 : 0x80)); - WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mb[1] ? 0 : 0x80)); - WriteMacInt8(tmp_data + 3, ((my >> 3) & 0x70) | ((mx >> 7) & 0x07) | (mb[2] ? 0x08 : 0x88)); - } else { - // 100/200 dpi mode - WriteMacInt8(tmp_data, 2); - WriteMacInt8(tmp_data + 1, (my & 0x7f) | (mb[0] ? 0 : 0x80)); - WriteMacInt8(tmp_data + 2, (mx & 0x7f) | (mb[1] ? 0 : 0x80)); - } - r.a[0] = tmp_data; - r.a[1] = ReadMacInt32(mouse_base); - r.a[2] = ReadMacInt32(mouse_base + 4); - r.a[3] = adb_base; - r.d[0] = (mouse_reg_3[0] << 4) | 0x0c; // Talk 0 - Execute68k(r.a[1], &r); - - old_mouse_button[0] = mb[0]; - old_mouse_button[1] = mb[1]; - old_mouse_button[2] = mb[2]; - } -*/ } else { // Update mouse position (absolute) @@ -487,35 +459,6 @@ void ADBInterrupt(void) } } - -/* // Send mouse button events - if (mb[0] != old_mouse_button[0] || mb[1] != old_mouse_button[1] || mb[2] != old_mouse_button[2]) { - uint32 mouse_base = adb_base + 16; - - // Call mouse ADB handler - if (mouse_reg_3[1] == 4) { - // Extended mouse protocol - WriteMacInt8(tmp_data, 3); - WriteMacInt8(tmp_data + 1, mb[0] ? 0 : 0x80); - WriteMacInt8(tmp_data + 2, mb[1] ? 0 : 0x80); - WriteMacInt8(tmp_data + 3, mb[2] ? 0x08 : 0x88); - } else { - // 100/200 dpi mode - WriteMacInt8(tmp_data, 2); - WriteMacInt8(tmp_data + 1, mb[0] ? 0 : 0x80); - WriteMacInt8(tmp_data + 2, mb[1] ? 0 : 0x80); - } - r.a[0] = tmp_data; - r.a[1] = ReadMacInt32(mouse_base); - r.a[2] = ReadMacInt32(mouse_base + 4); - r.a[3] = adb_base; - r.d[0] = (mouse_reg_3[0] << 4) | 0x0c; // Talk 0 - Execute68k(r.a[1], &r); - - old_mouse_button[0] = mb[0]; - old_mouse_button[1] = mb[1]; - old_mouse_button[2] = mb[2]; - } */ } // Process accumulated keyboard events