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;
uint8_t flags;
uint16_t flags;
uint8_t resolution;
uint8_t sample_rate;
@@ -46,11 +46,12 @@ typedef struct {
uint8_t last_data[6];
} mouse_t;
#define FLAG_INTELLI 0x80 /* device is IntelliMouse */
#define FLAG_INTMODE 0x40 /* using Intellimouse mode */
#define FLAG_SCALED 0x20 /* enable delta scaling */
#define FLAG_ENABLED 0x10 /* dev is enabled for use */
#define FLAG_CTRLDAT 0x08 /* ctrl or data mode */
#define FLAG_5BTN 0x100 /* using Intellimouse Optical mode */
#define FLAG_INTELLI 0x80 /* device is IntelliMouse */
#define FLAG_INTMODE 0x40 /* using Intellimouse mode */
#define FLAG_SCALED 0x20 /* enable delta scaling */
#define FLAG_ENABLED 0x10 /* dev is enabled for use */
#define FLAG_CTRLDAT 0x08 /* ctrl or data mode */
int mouse_scan = 0;
@@ -156,14 +157,24 @@ ps2_write(uint8_t val, void *priv)
keyboard_at_adddata_mouse(temp);
keyboard_at_adddata_mouse(dev->x & 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;
case 0xf2: /* read ID */
keyboard_at_adddata_mouse(0xfa);
if (dev->flags & FLAG_INTMODE)
keyboard_at_adddata_mouse(0x03);
keyboard_at_adddata_mouse((dev->flags & FLAG_5BTN) ? 0x04 : 0x03);
else
keyboard_at_adddata_mouse(0x00);
break;
@@ -210,8 +221,17 @@ mouse_reset:
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;
}
}
}
@@ -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[1]);
keyboard_at_adddata_mouse(buff[2]);
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);
}
dev->x = dev->y = dev->z = 0;
}
@@ -299,13 +328,15 @@ mouse_ps2_init(const device_t *info)
if (i > 2)
dev->flags |= FLAG_INTELLI;
if (i == 4) i = 3;
/* Hook into the general AT Keyboard driver. */
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. */
mouse_set_buttons((dev->flags & FLAG_INTELLI) ? 3 : 2);
mouse_set_buttons(i);
/* Return our private data to the I/O layer. */
return (dev);
@@ -333,10 +364,11 @@ static const device_config_t ps2_config[] = {
.file_filter = "",
.spinner = { 0 },
.selection = {
{ .description = "Two", .value = 2 },
{ .description = "Three", .value = 3 },
{ .description = "Wheel", .value = 4 },
{ .description = "" }
{ .description = "Two", .value = 2 },
{ .description = "Three", .value = 3 },
{ .description = "Wheel", .value = 4 },
{ .description = "Five + Wheel", .value = 5 },
{ .description = "" }
}
},
{

View File

@@ -706,7 +706,7 @@ mouse_poll()
mouse_y = mousedata.deltay;
mouse_z = mousedata.deltaz;
mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0;
mouse_buttons = mousedata.mousebuttons;
mouse_buttons = mousedata.mousebuttons;
SDL_UnlockMutex(mousemutex);
}
@@ -1171,6 +1171,12 @@ main(int argc, char **argv)
case SDL_BUTTON_MIDDLE:
buttonmask = 4;
break;
case SDL_BUTTON_X1:
buttonmask = 8;
break;
case SDL_BUTTON_X2:
buttonmask = 16;
break;
}
SDL_LockMutex(mousemutex);
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)
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) {
mousestate.dwheel += (SHORT) state.usButtonData / 120;
}