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
|
|
|
*
|
2018-03-19 01:02:04 +01:00
|
|
|
* Version: @(#)mouse.c 1.0.23 2018/03/18
|
2017-12-04 11:59:26 -05:00
|
|
|
*
|
|
|
|
|
* 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
|
|
|
*
|
2018-01-26 13:35:50 +01:00
|
|
|
* Copyright 2016-2018 Miran Grca.
|
|
|
|
|
* Copyright 2017,2018 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;
|
2018-03-19 01:02:04 +01:00
|
|
|
const device_t *device;
|
2017-12-04 11:59:26 -05:00
|
|
|
} 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;
|
|
|
|
|
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
static const device_t mouse_none_device = {
|
2017-12-04 11:59:26 -05:00
|
|
|
"None",
|
|
|
|
|
0, MOUSE_TYPE_NONE,
|
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
|
NULL, NULL, NULL, NULL,
|
|
|
|
|
NULL
|
2017-06-21 00:41:34 -04:00
|
|
|
};
|
2018-03-19 01:02:04 +01:00
|
|
|
static const device_t mouse_internal_device = {
|
2017-12-04 11:59:26 -05:00
|
|
|
"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 },
|
|
|
|
|
{ "ps2", &mouse_ps2_device },
|
|
|
|
|
{ NULL, NULL }
|
2016-12-23 03:16:24 +01:00
|
|
|
};
|
2017-12-04 11:59:26 -05:00
|
|
|
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
static const device_t *mouse_curr;
|
2017-10-26 04:54:50 -04:00
|
|
|
static void *mouse_priv;
|
2017-12-10 02:08:37 -05:00
|
|
|
static int mouse_nbut;
|
2018-03-18 20:48:10 +01:00
|
|
|
static int (*mouse_dev_poll)();
|
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;
|
2017-12-10 02:08:37 -05:00
|
|
|
mouse_nbut = 0;
|
2018-03-18 20:48:10 +01:00
|
|
|
mouse_dev_poll = 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-10-26 04:54:50 -04:00
|
|
|
mouse_curr = NULL;
|
|
|
|
|
mouse_priv = NULL;
|
2017-12-10 02:08:37 -05:00
|
|
|
mouse_nbut = 0;
|
2018-03-18 20:48:10 +01:00
|
|
|
mouse_dev_poll = 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)
|
|
|
|
|
{
|
2018-01-29 01:19:49 +01:00
|
|
|
if (mouse_curr != NULL)
|
|
|
|
|
return; /* Mouse already initialized. */
|
|
|
|
|
|
2017-12-10 02:08:37 -05:00
|
|
|
pclog("MOUSE: reset(type=%d, '%s')\n",
|
|
|
|
|
mouse_type, mouse_devices[mouse_type].device->name);
|
2017-12-04 11:59:26 -05:00
|
|
|
|
|
|
|
|
/* 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-12-10 02:08:37 -05:00
|
|
|
/* Callback from the hardware driver. */
|
|
|
|
|
void
|
|
|
|
|
mouse_set_buttons(int buttons)
|
|
|
|
|
{
|
|
|
|
|
mouse_nbut = buttons;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-03-18 20:48:10 +01:00
|
|
|
if ((mouse_dev_poll != NULL) || (mouse_curr->available != NULL)) {
|
|
|
|
|
if (mouse_curr->available != NULL)
|
|
|
|
|
mouse_curr->available(mouse_x,mouse_y,mouse_z,mouse_buttons, mouse_priv);
|
|
|
|
|
else
|
|
|
|
|
mouse_dev_poll(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-10 02:08:37 -05:00
|
|
|
mouse_set_poll(int (*func)(int,int,int,int,void *), void *arg)
|
2017-11-05 01:57:04 -05:00
|
|
|
{
|
|
|
|
|
if (mouse_type != MOUSE_TYPE_INTERNAL) return;
|
|
|
|
|
|
2018-03-18 20:48:10 +01:00
|
|
|
mouse_dev_poll = 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-01-26 13:35:50 +01:00
|
|
|
int
|
|
|
|
|
mouse_has_config(int mouse)
|
|
|
|
|
{
|
|
|
|
|
if (mouse_devices[mouse].device == NULL) return(0);
|
|
|
|
|
|
|
|
|
|
return(mouse_devices[mouse].device->config ? 1 : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
const device_t *
|
2017-12-10 02:08:37 -05:00
|
|
|
mouse_get_device(int mouse)
|
|
|
|
|
{
|
|
|
|
|
return(mouse_devices[mouse].device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-06 17:48:33 +02:00
|
|
|
int
|
2017-12-10 02:08:37 -05:00
|
|
|
mouse_get_buttons(void)
|
2016-12-23 03:16:24 +01:00
|
|
|
{
|
2017-12-10 02:08:37 -05:00
|
|
|
return(mouse_nbut);
|
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
|
|
|
}
|