OulanB's adb button buffer proposed change

This commit is contained in:
Andrew Tonner 2020-02-06 18:12:23 -08:00
parent c23967b03b
commit bb69145861

View File

@ -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