Added Microsoft Intellimouse emulation

This commit is contained in:
SarahW 2016-12-16 21:36:46 +00:00
commit 7f7c11edb2
11 changed files with 92 additions and 36 deletions

View file

@ -58,7 +58,7 @@ typedef struct mouse_amstrad_t
int oldb; int oldb;
} mouse_amstrad_t; } mouse_amstrad_t;
static void mouse_amstrad_poll(int x, int y, int b, void *p) static void mouse_amstrad_poll(int x, int y, int z, int b, void *p)
{ {
mouse_amstrad_t *mouse = (mouse_amstrad_t *)p; mouse_amstrad_t *mouse = (mouse_amstrad_t *)p;

View file

@ -221,7 +221,7 @@ typedef struct mouse_olim24_t
int x, y, b; int x, y, b;
} mouse_olim24_t; } mouse_olim24_t;
void mouse_olim24_poll(int x, int y, int b, void *p) void mouse_olim24_poll(int x, int y, int z, int b, void *p)
{ {
mouse_olim24_t *mouse = (mouse_olim24_t *)p; mouse_olim24_t *mouse = (mouse_olim24_t *)p;

View file

@ -9,6 +9,7 @@ static mouse_t *mouse_list[] =
{ {
&mouse_serial_microsoft, &mouse_serial_microsoft,
&mouse_ps2_2_button, &mouse_ps2_2_button,
&mouse_intellimouse,
&mouse_amstrad, &mouse_amstrad,
&mouse_olim24, &mouse_olim24,
NULL NULL
@ -31,10 +32,10 @@ void mouse_emu_close()
cur_mouse = NULL; cur_mouse = NULL;
} }
void mouse_poll(int x, int y, int b) void mouse_poll(int x, int y, int z, int b)
{ {
if (cur_mouse) if (cur_mouse)
cur_mouse->poll(x, y, b, mouse_p); cur_mouse->poll(x, y, z, b, mouse_p);
} }
char *mouse_get_name(int mouse) char *mouse_get_name(int mouse)

View file

@ -1,6 +1,6 @@
void mouse_emu_init(); void mouse_emu_init();
void mouse_emu_close(); void mouse_emu_close();
void mouse_poll(int x, int y, int b); void mouse_poll(int x, int y, int z, int b);
char *mouse_get_name(int mouse); char *mouse_get_name(int mouse);
int mouse_get_type(int mouse); int mouse_get_type(int mouse);
@ -10,12 +10,14 @@ int mouse_get_type(int mouse);
#define MOUSE_TYPE_AMSTRAD 2 #define MOUSE_TYPE_AMSTRAD 2
#define MOUSE_TYPE_OLIM24 3 #define MOUSE_TYPE_OLIM24 3
#define MOUSE_TYPE_3BUTTON (1 << 31)
typedef struct typedef struct
{ {
char name[80]; char name[80];
void *(*init)(); void *(*init)();
void (*close)(void *p); void (*close)(void *p);
uint8_t (*poll)(int x, int y, int b, void *p); uint8_t (*poll)(int x, int y, int z, int b, void *p);
int type; int type;
} mouse_t; } mouse_t;

View file

@ -28,7 +28,12 @@ typedef struct mouse_ps2_t
int cd; int cd;
int x, y, b; int x, y, z, b;
int is_intellimouse;
int intellimouse_mode;
uint8_t last_data[6];
} mouse_ps2_t; } mouse_ps2_t;
void mouse_ps2_write(uint8_t val, void *p) void mouse_ps2_write(uint8_t val, void *p)
@ -92,7 +97,10 @@ void mouse_ps2_write(uint8_t val, void *p)
case 0xf2: /*Read ID*/ case 0xf2: /*Read ID*/
keyboard_at_adddata_mouse(0xfa); keyboard_at_adddata_mouse(0xfa);
keyboard_at_adddata_mouse(0x00); if (mouse->intellimouse_mode)
keyboard_at_adddata_mouse(0x03);
else
keyboard_at_adddata_mouse(0x00);
break; break;
case 0xf3: /*Set sample rate*/ case 0xf3: /*Set sample rate*/
@ -113,6 +121,7 @@ void mouse_ps2_write(uint8_t val, void *p)
case 0xff: /*Reset*/ case 0xff: /*Reset*/
mouse->mode = MOUSE_STREAM; mouse->mode = MOUSE_STREAM;
mouse->flags = 0; mouse->flags = 0;
mouse->intellimouse_mode = 0;
keyboard_at_adddata_mouse(0xfa); keyboard_at_adddata_mouse(0xfa);
keyboard_at_adddata_mouse(0xaa); keyboard_at_adddata_mouse(0xaa);
keyboard_at_adddata_mouse(0x00); keyboard_at_adddata_mouse(0x00);
@ -122,14 +131,29 @@ void mouse_ps2_write(uint8_t val, void *p)
// fatal("mouse_ps2 : Bad command %02X\n", val, mouse->command); // fatal("mouse_ps2 : Bad command %02X\n", val, mouse->command);
} }
} }
if (mouse->is_intellimouse)
{
int c;
for (c = 0; c < 5; c++)
mouse->last_data[c] = mouse->last_data[c+1];
mouse->last_data[5] = val;
if (mouse->last_data[0] == 0xf3 && mouse->last_data[1] == 0xc8 &&
mouse->last_data[2] == 0xf3 && mouse->last_data[3] == 0x64 &&
mouse->last_data[4] == 0xf3 && mouse->last_data[5] == 0x50)
mouse->intellimouse_mode = 1;
}
} }
void mouse_ps2_poll(int x, int y, int b, void *p) void mouse_ps2_poll(int x, int y, int z, int b, void *p)
{ {
mouse_ps2_t *mouse = (mouse_ps2_t *)p; mouse_ps2_t *mouse = (mouse_ps2_t *)p;
uint8_t packet[3] = {0x08, 0, 0}; uint8_t packet[3] = {0x08, 0, 0};
if (!x && !y && b == mouse->b) if (!x && !y && !z && b == mouse->b)
return; return;
if (!mouse_scan) if (!mouse_scan)
@ -137,37 +161,44 @@ void mouse_ps2_poll(int x, int y, int b, void *p)
mouse->x += x; mouse->x += x;
mouse->y -= y; mouse->y -= y;
mouse->z -= z;
if (mouse->mode == MOUSE_STREAM && (mouse->flags & MOUSE_ENABLE) && if (mouse->mode == MOUSE_STREAM && (mouse->flags & MOUSE_ENABLE) &&
((mouse_queue_end - mouse_queue_start) & 0xf) < 13) ((mouse_queue_end - mouse_queue_start) & 0xf) < 13)
{ {
mouse->b = b; mouse->b = b;
// pclog("Send packet : %i %i\n", ps2_x, ps2_y); // pclog("Send packet : %i %i\n", ps2_x, ps2_y);
if (mouse->x > 255) if (mouse->x > 255)
mouse->x = 255; mouse->x = 255;
if (mouse->x < -256) if (mouse->x < -256)
mouse->x = -256; mouse->x = -256;
if (mouse->y > 255) if (mouse->y > 255)
mouse->y = 255; mouse->y = 255;
if (mouse->y < -256) if (mouse->y < -256)
mouse->y = -256; mouse->y = -256;
if (mouse->z < -8)
mouse->z = -8;
if (mouse->z > 7)
mouse->z = 7;
if (mouse->x < 0) if (mouse->x < 0)
packet[0] |= 0x10; packet[0] |= 0x10;
if (mouse->y < 0) if (mouse->y < 0)
packet[0] |= 0x20; packet[0] |= 0x20;
if (mouse_buttons & 1) if (mouse_buttons & 1)
packet[0] |= 1; packet[0] |= 1;
if (mouse_buttons & 2) if (mouse_buttons & 2)
packet[0] |= 2; packet[0] |= 2;
if (mouse_buttons & 4) if ((mouse_buttons & 4) && (mouse_get_type(mouse_type) & MOUSE_TYPE_3BUTTON))
packet[0] |= 4; packet[0] |= 4;
packet[1] = mouse->x & 0xff; packet[1] = mouse->x & 0xff;
packet[2] = mouse->y & 0xff; packet[2] = mouse->y & 0xff;
mouse->x = mouse->y = 0;
keyboard_at_adddata_mouse(packet[0]); keyboard_at_adddata_mouse(packet[0]);
keyboard_at_adddata_mouse(packet[1]); keyboard_at_adddata_mouse(packet[1]);
keyboard_at_adddata_mouse(packet[2]); keyboard_at_adddata_mouse(packet[2]);
if (mouse->intellimouse_mode)
keyboard_at_adddata_mouse(mouse->z);
mouse->x = mouse->y = mouse->z = 0;
} }
} }
@ -187,6 +218,15 @@ void *mouse_ps2_init()
return mouse; return mouse;
} }
void *mouse_intellimouse_init()
{
mouse_ps2_t *mouse = mouse_ps2_init();
mouse->is_intellimouse = 1;
return mouse;
}
void mouse_ps2_close(void *p) void mouse_ps2_close(void *p)
{ {
mouse_ps2_t *mouse = (mouse_ps2_t *)p; mouse_ps2_t *mouse = (mouse_ps2_t *)p;
@ -202,3 +242,11 @@ mouse_t mouse_ps2_2_button =
mouse_ps2_poll, mouse_ps2_poll,
MOUSE_TYPE_PS2 MOUSE_TYPE_PS2
}; };
mouse_t mouse_intellimouse =
{
"Microsoft Intellimouse (PS/2)",
mouse_intellimouse_init,
mouse_ps2_close,
mouse_ps2_poll,
MOUSE_TYPE_PS2 | MOUSE_TYPE_3BUTTON
};

View file

@ -1 +1,2 @@
extern mouse_t mouse_ps2_2_button; extern mouse_t mouse_ps2_2_button;
extern mouse_t mouse_intellimouse;

View file

@ -11,7 +11,7 @@ typedef struct mouse_serial_t
SERIAL *serial; SERIAL *serial;
} mouse_serial_t; } mouse_serial_t;
void mouse_serial_poll(int x, int y, int b, void *p) void mouse_serial_poll(int x, int y, int z, int b, void *p)
{ {
mouse_serial_t *mouse = (mouse_serial_t *)p; mouse_serial_t *mouse = (mouse_serial_t *)p;
SERIAL *serial = mouse->serial; SERIAL *serial = mouse->serial;

View file

@ -106,15 +106,15 @@ uint8_t cgastat;
int pollmouse_delay = 2; int pollmouse_delay = 2;
void pollmouse() void pollmouse()
{ {
int x,y; int x, y, z;
// return; // return;
pollmouse_delay--; pollmouse_delay--;
if (pollmouse_delay) return; if (pollmouse_delay) return;
pollmouse_delay = 2; pollmouse_delay = 2;
mouse_poll_host(); mouse_poll_host();
mouse_get_mickeys(&x,&y); mouse_get_mickeys(&x, &y, &z);
if (mouse_poll) if (mouse_poll)
mouse_poll(x, y, mouse_buttons); mouse_poll(x, y, z, mouse_buttons);
// if (mousecapture) position_mouse(64,64); // if (mousecapture) position_mouse(64,64);
} }
@ -500,7 +500,7 @@ void runpc()
if (win_title_update) if (win_title_update)
{ {
win_title_update=0; win_title_update=0;
sprintf(s, "PCem v11 - %i%% - %s - %s - %s", fps, model_getname(), models[model].cpu[cpu_manufacturer].cpus[cpu].name, (!mousecapture) ? "Click to capture mouse" : "Press CTRL-END or middle button to release mouse"); sprintf(s, "PCem v11 - %i%% - %s - %s - %s", fps, model_getname(), models[model].cpu[cpu_manufacturer].cpus[cpu].name, (!mousecapture) ? "Click to capture mouse" : ((mouse_get_type(mouse_type) & MOUSE_TYPE_3BUTTON) ? "Press CTRL-END to release mouse" : "Press CTRL-END or middle button to release mouse"));
set_window_title(s); set_window_title(s);
} }
done++; done++;

View file

@ -6,7 +6,7 @@ extern "C" {
void mouse_close(); void mouse_close();
extern int mouse_buttons; extern int mouse_buttons;
void mouse_poll_host(); void mouse_poll_host();
void mouse_get_mickeys(int *x, int *y); void mouse_get_mickeys(int *x, int *y, int *z);
extern int mousecapture; extern int mousecapture;
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -11,12 +11,12 @@ extern "C" void pclog(const char *format, ...);
extern "C" void mouse_init(); extern "C" void mouse_init();
extern "C" void mouse_close(); extern "C" void mouse_close();
extern "C" void mouse_poll_host(); extern "C" void mouse_poll_host();
extern "C" void mouse_get_mickeys(int *x, int *y); extern "C" void mouse_get_mickeys(int *x, int *y, int *z);
static LPDIRECTINPUT lpdi; static LPDIRECTINPUT lpdi;
static LPDIRECTINPUTDEVICE lpdi_mouse = NULL; static LPDIRECTINPUTDEVICE lpdi_mouse = NULL;
static DIMOUSESTATE mousestate; static DIMOUSESTATE mousestate;
static int mouse_x = 0, mouse_y = 0; static int mouse_x = 0, mouse_y = 0, mouse_z = 0;
int mouse_buttons = 0; int mouse_buttons = 0;
void mouse_init() void mouse_init()
@ -58,13 +58,15 @@ void mouse_poll_host()
mouse_buttons |= 4; mouse_buttons |= 4;
mouse_x += mousestate.lX; mouse_x += mousestate.lX;
mouse_y += mousestate.lY; mouse_y += mousestate.lY;
mouse_z += mousestate.lZ/120;
if (!mousecapture && !video_fullscreen) if (!mousecapture && !video_fullscreen)
mouse_x = mouse_y = mouse_buttons = 0; mouse_x = mouse_y = mouse_z = mouse_buttons = 0;
} }
void mouse_get_mickeys(int *x, int *y) void mouse_get_mickeys(int *x, int *y, int *z)
{ {
*x = mouse_x; *x = mouse_x;
*y = mouse_y; *y = mouse_y;
mouse_x = mouse_y = 0; *z = mouse_z;
mouse_x = mouse_y = mouse_z = 0;
} }

View file

@ -22,6 +22,7 @@
#include "cpu.h" #include "cpu.h"
#include "ide.h" #include "ide.h"
#include "model.h" #include "model.h"
#include "mouse.h"
#include "nvr.h" #include "nvr.h"
#include "sound.h" #include "sound.h"
#include "thread.h" #include "thread.h"
@ -1261,7 +1262,8 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
break; break;
case WM_MBUTTONUP: case WM_MBUTTONUP:
releasemouse(); if (!(mouse_get_type(mouse_type) & MOUSE_TYPE_3BUTTON))
releasemouse();
break; break;
case WM_ENTERMENULOOP: case WM_ENTERMENULOOP: