Add option for 5-button PS/2 mouse

This commit is contained in:
Cacodemon345
2022-10-28 23:51:38 +06:00
parent e5268075fb
commit b388cb552f
3 changed files with 67 additions and 19 deletions

View File

@@ -36,7 +36,7 @@ typedef struct {
int mode; int mode;
uint8_t flags; uint16_t flags;
uint8_t resolution; uint8_t resolution;
uint8_t sample_rate; uint8_t sample_rate;
@@ -46,6 +46,7 @@ typedef struct {
uint8_t last_data[6]; uint8_t last_data[6];
} mouse_t; } mouse_t;
#define FLAG_5BTN 0x100 /* using Intellimouse Optical mode */
#define FLAG_INTELLI 0x80 /* device is IntelliMouse */ #define FLAG_INTELLI 0x80 /* device is IntelliMouse */
#define FLAG_INTMODE 0x40 /* using Intellimouse mode */ #define FLAG_INTMODE 0x40 /* using Intellimouse mode */
#define FLAG_SCALED 0x20 /* enable delta scaling */ #define FLAG_SCALED 0x20 /* enable delta scaling */
@@ -156,14 +157,24 @@ ps2_write(uint8_t val, void *priv)
keyboard_at_adddata_mouse(temp); keyboard_at_adddata_mouse(temp);
keyboard_at_adddata_mouse(dev->x & 0xff); keyboard_at_adddata_mouse(dev->x & 0xff);
keyboard_at_adddata_mouse(dev->y & 0xff); keyboard_at_adddata_mouse(dev->y & 0xff);
if (dev->flags & FLAG_INTMODE)
keyboard_at_adddata_mouse(dev->z); if (dev->flags & FLAG_INTMODE) {
int temp_z = dev->z;
if ((dev->flags & FLAG_5BTN)) {
temp_z &= 0xF;
if (mouse_buttons & 8)
temp_z |= 0x10;
if (mouse_buttons & 16)
temp_z |= 0x20;
}
keyboard_at_adddata_mouse(temp_z);
}
break; break;
case 0xf2: /* read ID */ case 0xf2: /* read ID */
keyboard_at_adddata_mouse(0xfa); keyboard_at_adddata_mouse(0xfa);
if (dev->flags & FLAG_INTMODE) if (dev->flags & FLAG_INTMODE)
keyboard_at_adddata_mouse(0x03); keyboard_at_adddata_mouse((dev->flags & FLAG_5BTN) ? 0x04 : 0x03);
else else
keyboard_at_adddata_mouse(0x00); keyboard_at_adddata_mouse(0x00);
break; break;
@@ -210,9 +221,18 @@ mouse_reset:
dev->last_data[5] = val; dev->last_data[5] = val;
if (dev->last_data[0] == 0xf3 && dev->last_data[1] == 0xc8 && dev->last_data[2] == 0xf3 && dev->last_data[3] == 0x64 && dev->last_data[4] == 0xf3 && dev->last_data[5] == 0x50) if (dev->last_data[0] == 0xf3 && dev->last_data[1] == 0xc8
&& dev->last_data[2] == 0xf3 && dev->last_data[3] == 0xc8
&& dev->last_data[4] == 0xf3 && dev->last_data[5] == 0x50
&& mouse_get_buttons() == 5) {
dev->flags |= FLAG_INTMODE | FLAG_5BTN;
}
else if (dev->last_data[0] == 0xf3 && dev->last_data[1] == 0xc8
&& dev->last_data[2] == 0xf3 && dev->last_data[3] == 0x64
&& dev->last_data[4] == 0xf3 && dev->last_data[5] == 0x50) {
dev->flags |= FLAG_INTMODE; dev->flags |= FLAG_INTMODE;
} }
}
} }
static int static int
@@ -269,8 +289,17 @@ ps2_poll(int x, int y, int z, int b, void *priv)
keyboard_at_adddata_mouse(buff[0]); keyboard_at_adddata_mouse(buff[0]);
keyboard_at_adddata_mouse(buff[1]); keyboard_at_adddata_mouse(buff[1]);
keyboard_at_adddata_mouse(buff[2]); keyboard_at_adddata_mouse(buff[2]);
if (dev->flags & FLAG_INTMODE) if (dev->flags & FLAG_INTMODE) {
keyboard_at_adddata_mouse(dev->z); int temp_z = dev->z;
if ((dev->flags & FLAG_5BTN)) {
temp_z &= 0xF;
if (mouse_buttons & 8)
temp_z |= 0x10;
if (mouse_buttons & 16)
temp_z |= 0x20;
}
keyboard_at_adddata_mouse(temp_z);
}
dev->x = dev->y = dev->z = 0; dev->x = dev->y = dev->z = 0;
} }
@@ -299,13 +328,15 @@ mouse_ps2_init(const device_t *info)
if (i > 2) if (i > 2)
dev->flags |= FLAG_INTELLI; dev->flags |= FLAG_INTELLI;
if (i == 4) i = 3;
/* Hook into the general AT Keyboard driver. */ /* Hook into the general AT Keyboard driver. */
keyboard_at_set_mouse(ps2_write, dev); keyboard_at_set_mouse(ps2_write, dev);
mouse_ps2_log("%s: buttons=%d\n", dev->name, (dev->flags & FLAG_INTELLI) ? 3 : 2); mouse_ps2_log("%s: buttons=%d\n", dev->name, i);
/* Tell them how many buttons we have. */ /* Tell them how many buttons we have. */
mouse_set_buttons((dev->flags & FLAG_INTELLI) ? 3 : 2); mouse_set_buttons(i);
/* Return our private data to the I/O layer. */ /* Return our private data to the I/O layer. */
return (dev); return (dev);
@@ -336,6 +367,7 @@ static const device_config_t ps2_config[] = {
{ .description = "Two", .value = 2 }, { .description = "Two", .value = 2 },
{ .description = "Three", .value = 3 }, { .description = "Three", .value = 3 },
{ .description = "Wheel", .value = 4 }, { .description = "Wheel", .value = 4 },
{ .description = "Five + Wheel", .value = 5 },
{ .description = "" } { .description = "" }
} }
}, },

View File

@@ -1171,6 +1171,12 @@ main(int argc, char **argv)
case SDL_BUTTON_MIDDLE: case SDL_BUTTON_MIDDLE:
buttonmask = 4; buttonmask = 4;
break; break;
case SDL_BUTTON_X1:
buttonmask = 8;
break;
case SDL_BUTTON_X2:
buttonmask = 16;
break;
} }
SDL_LockMutex(mousemutex); SDL_LockMutex(mousemutex);
if (event.button.state == SDL_PRESSED) { if (event.button.state == SDL_PRESSED) {

View File

@@ -81,6 +81,16 @@ win_mouse_handle(PRAWINPUT raw)
else if (state.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_UP) else if (state.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_UP)
mousestate.buttons &= ~2; mousestate.buttons &= ~2;
if (state.usButtonFlags & RI_MOUSE_BUTTON_4_DOWN)
mousestate.buttons |= 8;
else if (state.usButtonFlags & RI_MOUSE_BUTTON_4_UP)
mousestate.buttons &= ~8;
if (state.usButtonFlags & RI_MOUSE_BUTTON_5_DOWN)
mousestate.buttons |= 16;
else if (state.usButtonFlags & RI_MOUSE_BUTTON_5_UP)
mousestate.buttons &= ~16;
if (state.usButtonFlags & RI_MOUSE_WHEEL) { if (state.usButtonFlags & RI_MOUSE_WHEEL) {
mousestate.dwheel += (SHORT) state.usButtonData / 120; mousestate.dwheel += (SHORT) state.usButtonData / 120;
} }