2017-06-21 00:41:34 -04:00
|
|
|
/*
|
|
|
|
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
|
|
|
|
* running old operating systems and software designed for IBM
|
|
|
|
|
* PC systems and compatibles from 1981 through fairly recent
|
|
|
|
|
* system designs based on the PCI bus.
|
|
|
|
|
*
|
|
|
|
|
* This file is part of the 86Box distribution.
|
|
|
|
|
*
|
|
|
|
|
* Common driver module for MOUSE devices.
|
|
|
|
|
*
|
2017-12-04 11:59:26 -05:00
|
|
|
* TODO: Add the Genius bus- and serial mouse.
|
|
|
|
|
* Remove the '3-button' flag from mouse types.
|
2017-06-21 00:41:34 -04:00
|
|
|
*
|
2017-12-04 11:59:26 -05:00
|
|
|
* Version: @(#)mouse.c 1.0.17 2017/12/03
|
|
|
|
|
*
|
|
|
|
|
* Authors: Miran Grca, <mgrca8@gmail.com>
|
2017-06-21 00:41:34 -04:00
|
|
|
* Fred N. van Kempen, <decwiz@yahoo.com>
|
2017-10-10 03:07:29 -04:00
|
|
|
*
|
2017-09-25 04:31:20 -04:00
|
|
|
* Copyright 2016,2017 Miran Grca.
|
2017-12-04 11:59:26 -05:00
|
|
|
* Copyright 2017 Fred N. van Kempen.
|
2017-06-21 00:41:34 -04:00
|
|
|
*/
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <wchar.h>
|
2017-11-02 02:28:00 -05:00
|
|
|
#include "86box.h"
|
2017-06-16 16:00:44 -04:00
|
|
|
#include "device.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "mouse.h"
|
2017-12-04 11:59:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
const char *internal_name;
|
|
|
|
|
device_t *device;
|
|
|
|
|
} mouse_t;
|
2017-06-21 00:41:34 -04:00
|
|
|
|
|
|
|
|
|
2017-10-23 05:20:18 -04:00
|
|
|
int mouse_type = 0;
|
|
|
|
|
int mouse_x,
|
|
|
|
|
mouse_y,
|
|
|
|
|
mouse_z,
|
|
|
|
|
mouse_buttons;
|
|
|
|
|
|
|
|
|
|
|
2017-12-04 11:59:26 -05:00
|
|
|
static device_t mouse_none_device = {
|
|
|
|
|
"None",
|
|
|
|
|
0, MOUSE_TYPE_NONE,
|
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
|
NULL, NULL, NULL, NULL,
|
|
|
|
|
NULL
|
2017-06-21 00:41:34 -04:00
|
|
|
};
|
2017-12-04 11:59:26 -05:00
|
|
|
static device_t mouse_internal_device = {
|
|
|
|
|
"Internal Mouse",
|
|
|
|
|
0, MOUSE_TYPE_INTERNAL,
|
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
|
NULL, NULL, NULL, NULL,
|
|
|
|
|
NULL
|
2017-11-05 01:57:04 -05:00
|
|
|
};
|
|
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
|
2017-12-04 11:59:26 -05:00
|
|
|
static mouse_t mouse_devices[] = {
|
|
|
|
|
{ "none", &mouse_none_device },
|
|
|
|
|
{ "internal", &mouse_internal_device },
|
|
|
|
|
{ "logibus", &mouse_logibus_device },
|
|
|
|
|
{ "msbus", &mouse_msinport_device },
|
2017-05-29 01:18:32 +02:00
|
|
|
#if 0
|
2017-12-04 11:59:26 -05:00
|
|
|
{ "genibus", &mouse_genibus_device },
|
2017-05-05 01:49:42 +02:00
|
|
|
#endif
|
2017-12-04 11:59:26 -05:00
|
|
|
{ "mssystems", &mouse_mssystems_device },
|
|
|
|
|
{ "msserial", &mouse_msserial_device },
|
|
|
|
|
{ "lserial", &mouse_lserial_device },
|
|
|
|
|
{ "mswheel", &mouse_mswheel_device },
|
|
|
|
|
{ "ps2", &mouse_ps2_device },
|
|
|
|
|
{ "intellimouse", &mouse_ps2ms_device },
|
|
|
|
|
{ NULL, NULL }
|
2016-12-23 03:16:24 +01:00
|
|
|
};
|
2017-12-04 11:59:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
static device_t *mouse_curr;
|
2017-10-26 04:54:50 -04:00
|
|
|
static void *mouse_priv;
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
|
2017-12-04 11:59:26 -05:00
|
|
|
/* Initialize the mouse module. */
|
2017-05-06 17:48:33 +02:00
|
|
|
void
|
2017-12-04 11:59:26 -05:00
|
|
|
mouse_init(void)
|
2016-12-23 03:16:24 +01:00
|
|
|
{
|
2017-10-23 05:20:18 -04:00
|
|
|
/* Initialize local data. */
|
|
|
|
|
mouse_x = mouse_y = mouse_z = 0;
|
|
|
|
|
mouse_buttons = 0x00;
|
|
|
|
|
|
2017-12-04 11:59:26 -05:00
|
|
|
mouse_type = MOUSE_TYPE_NONE;
|
|
|
|
|
mouse_curr = NULL;
|
|
|
|
|
mouse_priv = NULL;
|
2016-12-23 03:16:24 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
|
2017-05-06 17:48:33 +02:00
|
|
|
void
|
2017-12-04 11:59:26 -05:00
|
|
|
mouse_close(void)
|
2016-12-23 03:16:24 +01:00
|
|
|
{
|
2017-12-04 11:59:26 -05:00
|
|
|
if (mouse_curr == NULL) return;
|
2017-06-21 00:41:34 -04:00
|
|
|
|
2017-12-04 11:59:26 -05:00
|
|
|
if (mouse_curr->close != NULL)
|
|
|
|
|
mouse_curr->close(mouse_priv);
|
2017-06-21 00:41:34 -04:00
|
|
|
|
2017-10-26 04:54:50 -04:00
|
|
|
mouse_curr = NULL;
|
|
|
|
|
mouse_priv = NULL;
|
2016-12-23 03:16:24 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
|
2017-12-04 11:59:26 -05:00
|
|
|
void
|
|
|
|
|
mouse_reset(void)
|
|
|
|
|
{
|
|
|
|
|
pclog("MOUSE: reset(type=%d)\n", mouse_type);
|
|
|
|
|
|
|
|
|
|
/* Close previous mouse, if open. */
|
|
|
|
|
mouse_close();
|
|
|
|
|
|
|
|
|
|
/* Clear local data. */
|
|
|
|
|
mouse_x = mouse_y = mouse_z = 0;
|
|
|
|
|
mouse_buttons = 0x00;
|
|
|
|
|
|
|
|
|
|
/* If no mouse configured, we're done. */
|
|
|
|
|
if (mouse_type == 0) return;
|
|
|
|
|
|
|
|
|
|
mouse_curr = mouse_devices[mouse_type].device;
|
|
|
|
|
|
|
|
|
|
if (mouse_curr != NULL)
|
|
|
|
|
mouse_priv = device_add(mouse_curr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-10-19 04:27:04 -04:00
|
|
|
void
|
|
|
|
|
mouse_process(void)
|
|
|
|
|
{
|
|
|
|
|
static int poll_delay = 2;
|
|
|
|
|
|
2017-12-04 11:59:26 -05:00
|
|
|
if (mouse_curr == NULL) return;
|
|
|
|
|
|
2017-10-19 04:27:04 -04:00
|
|
|
if (--poll_delay) return;
|
|
|
|
|
|
2017-12-04 11:59:26 -05:00
|
|
|
mouse_poll();
|
2017-10-19 04:27:04 -04:00
|
|
|
|
2017-12-04 11:59:26 -05:00
|
|
|
if (mouse_curr->available != NULL) {
|
|
|
|
|
mouse_curr->available(mouse_x,mouse_y,mouse_z,mouse_buttons, mouse_priv);
|
2017-10-19 04:27:04 -04:00
|
|
|
|
2017-12-04 11:59:26 -05:00
|
|
|
/* Reset mouse deltas. */
|
|
|
|
|
mouse_x = mouse_y = mouse_z = 0;
|
|
|
|
|
}
|
2017-10-19 04:27:04 -04:00
|
|
|
|
|
|
|
|
poll_delay = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-11-05 01:57:04 -05:00
|
|
|
void
|
2017-12-04 11:59:26 -05:00
|
|
|
mouse_setpoll(int (*func)(int,int,int,int,void *), void *arg)
|
2017-11-05 01:57:04 -05:00
|
|
|
{
|
|
|
|
|
if (mouse_type != MOUSE_TYPE_INTERNAL) return;
|
|
|
|
|
|
2017-12-04 11:59:26 -05:00
|
|
|
mouse_curr->available = func;
|
2017-11-05 01:57:04 -05:00
|
|
|
mouse_priv = arg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-06 17:48:33 +02:00
|
|
|
char *
|
|
|
|
|
mouse_get_name(int mouse)
|
2016-12-23 03:16:24 +01:00
|
|
|
{
|
2017-12-04 11:59:26 -05:00
|
|
|
return((char *)mouse_devices[mouse].device->name);
|
2016-12-23 03:16:24 +01:00
|
|
|
}
|
2017-05-05 01:49:42 +02:00
|
|
|
|
|
|
|
|
|
2017-05-06 17:48:33 +02:00
|
|
|
char *
|
|
|
|
|
mouse_get_internal_name(int mouse)
|
2017-05-05 01:49:42 +02:00
|
|
|
{
|
2017-12-04 11:59:26 -05:00
|
|
|
return((char *)mouse_devices[mouse].internal_name);
|
2017-05-05 01:49:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-06 17:48:33 +02:00
|
|
|
int
|
|
|
|
|
mouse_get_from_internal_name(char *s)
|
2017-05-05 01:49:42 +02:00
|
|
|
{
|
|
|
|
|
int c = 0;
|
|
|
|
|
|
2017-12-04 11:59:26 -05:00
|
|
|
while (mouse_devices[c].internal_name != NULL) {
|
|
|
|
|
if (! strcmp((char *)mouse_devices[c].internal_name, s)) {
|
2017-05-05 01:49:42 +02:00
|
|
|
return(c);
|
2017-12-04 11:59:26 -05:00
|
|
|
}
|
2017-05-05 01:49:42 +02:00
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-06 17:48:33 +02:00
|
|
|
int
|
|
|
|
|
mouse_get_type(int mouse)
|
2016-12-23 03:16:24 +01:00
|
|
|
{
|
2017-12-04 11:59:26 -05:00
|
|
|
return(mouse_devices[mouse].device->local);
|
2017-05-05 01:49:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Return number of MOUSE types we know about. */
|
2017-05-06 17:48:33 +02:00
|
|
|
int
|
|
|
|
|
mouse_get_ndev(void)
|
2017-05-05 01:49:42 +02:00
|
|
|
{
|
2017-12-04 11:59:26 -05:00
|
|
|
return((sizeof(mouse_devices)/sizeof(mouse_t)) - 1);
|
2016-12-23 03:16:24 +01:00
|
|
|
}
|