31
35
#include "cmdline.h"
32
36
#include "joystick.h"
34
39
#include "mousedrv.h"
35
40
#include "resources.h"
36
#ifdef HAS_TRANSLATION
37
41
#include "translate.h"
43
#define NEOS_RESET_CLK 100
44
struct alarm_s *neosmouse_alarm;
40
46
int _mouse_enabled = 0;
42
static int mouse_port;
51
int neos_and_amiga_buttons;
66
} neos_state = NEOS_IDLE;
68
void neos_get_new_movement(void)
72
new_x = mousedrv_get_x();
73
new_y = mousedrv_get_y();
74
neos_x = new_x - neos_lastx;
75
if (new_x < neos_lastx)
77
if (neos_lastx > 0x6f && new_x < 0x10)
82
else if (new_x > neos_lastx)
84
if(neos_lastx < 0x10 && new_x > 0x6f)
91
neos_y = new_y - neos_lasty;
92
if (new_y < neos_lasty)
94
if (neos_lasty > 0x6f && new_y < 0x10)
99
else if (new_y > neos_lasty)
101
if (neos_lasty < 0x10 && new_y > 0x6f)
108
neos_x = (neos_x & 0x80) ? (neos_x / 2) | 0x80 : neos_x / 2;
109
neos_y = (neos_y & 0x80) ? (neos_y / 2) | 0x80 : neos_y / 2;
113
void neos_mouse_store(BYTE val)
118
if (((val & 16) ^ (neos_prev & 16)) && ((val & 16)==0))
121
neos_get_new_movement();
125
if (((val & 16) ^ (neos_prev & 16)) && ((val & 16)!=0))
129
if (((val & 16) ^ (neos_prev & 16)) && ((val & 16)==0))
133
if (((val & 16) ^ (neos_prev & 16)) && ((val & 16)!=0))
136
alarm_set(neosmouse_alarm, maincpu_clk + NEOS_RESET_CLK);
149
BYTE neos_mouse_read(void)
154
return ((neos_x >> 4) & 0xf) | 0xf0;
157
return (neos_x & 0xf) | 0xf0;
160
return ((neos_y >> 4) & 0xf) | 0xf0;
163
return (neos_y & 0xf) | 0xf0;
174
void neosmouse_alarm_handler(CLOCK offset, void *data)
176
alarm_unset(neosmouse_alarm);
177
neos_state = NEOS_IDLE;
180
/* Amiga mouse support is currently experimental */
182
BYTE amiga_mouse_table[4] = { 0x0, 0x1, 0x5, 0x4 };
184
/* the method below results in alot of overflows */
186
BYTE amiga_mouse_read(void)
190
new_x = mousedrv_get_x()/2;
191
new_y = (-mousedrv_get_y())/2;
193
return (amiga_mouse_table[new_x & 3] << 1) | amiga_mouse_table[new_y &
198
/* the alternate method below doesn't keep track of the speed of
199
the mouse movements, just the direction.
202
static BYTE old_x = 0;
203
static BYTE old_y = 0;
204
static BYTE x_count = 0;
205
static BYTE y_count = 0;
207
BYTE amiga_mouse_read(void)
210
signed char dir_x, dir_y;
212
/* get the new mouse values */
213
new_x = mousedrv_get_x();
214
new_y = (-mousedrv_get_y());
216
/* find out the x direction */
219
/* no direction, 0 */
226
if ((new_x - old_x) < (old_x + 256 - new_x))
233
/* left underflow, -1 */
239
if ((old_x - new_x) < (new_x + 256 - old_x))
246
/* right overflow, +1 */
252
/* find out the y direction */
261
if ((new_y - old_y) < (old_y + 256 - new_y))
272
if ((old_y - new_y) < (new_y + 256 - old_y))
283
/* store new values as old values */
287
/* add x direction to x counter */
290
/* add y direction to y counter */
293
return (amiga_mouse_table[x_count & 3] << 1) | amiga_mouse_table[y_count & 3] | 0xf0;
45
296
static int set_mouse_enabled(int val, void *param)
313
static int set_mouse_type(int val, void *param)
315
if (!((val >= 0) && (val <= 2)))
62
323
static const resource_int_t resources_int[] = {
63
324
{ "Mouse", 0, RES_EVENT_SAME, NULL,
64
325
&_mouse_enabled, set_mouse_enabled, NULL },
65
326
{ "Mouseport", 1, RES_EVENT_SAME, NULL,
66
327
&mouse_port, set_mouse_port, NULL },
328
{ "Mousetype", MOUSE_TYPE_1351, RES_EVENT_SAME, NULL,
329
&mouse_type, set_mouse_type, NULL },
75
338
return mousedrv_resources_init();
78
#ifdef HAS_TRANSLATION
79
static const cmdline_option_t cmdline_options[] = {
80
{ "-mouse", SET_RESOURCE, 1, NULL, NULL,
81
"Mouse", NULL, 0, IDCLS_ENABLE_1351_MOUSE },
82
{ "+mouse", SET_RESOURCE, 0, NULL, NULL,
83
"Mouse", NULL, 0, IDCLS_DISABLE_1351_MOUSE },
84
{ "-mouseport", SET_RESOURCE, 1, NULL, NULL,
85
"Mouseport", NULL, IDCLS_P_VALUE, IDCLS_SELECT_MOUSE_JOY_PORT },
89
static const cmdline_option_t cmdline_options[] = {
90
{ "-mouse", SET_RESOURCE, 1, NULL, NULL,
91
"Mouse", NULL, NULL, N_("Enable emulation of the 1351 proportional mouse") },
92
{ "+mouse", SET_RESOURCE, 0, NULL, NULL,
93
"Mouse", NULL, NULL, N_("Disable emulation of the 1351 proportional mouse") },
94
{ "-mouseport", SET_RESOURCE, 1, NULL, NULL,
95
"Mouseport", NULL, N_("<value>"), N_("Select the joystick port the mouse is attached to") },
341
static const cmdline_option_t cmdline_options[] = {
342
{ "-mouse", SET_RESOURCE, 0,
343
NULL, NULL, "Mouse", (void *)1,
344
USE_PARAM_STRING, USE_DESCRIPTION_ID,
345
IDCLS_UNUSED, IDCLS_ENABLE_MOUSE_GRAB,
347
{ "+mouse", SET_RESOURCE, 0,
348
NULL, NULL, "Mouse", (void *)0,
349
USE_PARAM_STRING, USE_DESCRIPTION_ID,
350
IDCLS_UNUSED, IDCLS_DISABLE_MOUSE_GRAB,
352
{ "-mouseport", SET_RESOURCE, 1,
353
NULL, NULL, "Mouseport", NULL,
354
USE_PARAM_ID, USE_DESCRIPTION_ID,
355
IDCLS_P_VALUE, IDCLS_SELECT_MOUSE_JOY_PORT,
357
{ "-mousetype", SET_RESOURCE, 1,
358
NULL, NULL, "Mousetype", NULL,
359
USE_PARAM_ID, USE_DESCRIPTION_ID,
360
IDCLS_P_VALUE, IDCLS_SELECT_MOUSE_TYPE,
100
365
int mouse_cmdline_options_init(void)
122
390
void mouse_button_right(int pressed)
125
joystick_set_value_or(mouse_port, 1);
127
joystick_set_value_and(mouse_port, ~1);
392
if (mouse_type != MOUSE_TYPE_1351)
396
neos_and_amiga_buttons |= 1;
400
neos_and_amiga_buttons &= ~1;
407
joystick_set_value_or(mouse_port, 1);
411
joystick_set_value_and(mouse_port, ~1);
131
416
BYTE mouse_get_x(void)
133
return mousedrv_get_x();
418
return ((mouse_type == MOUSE_TYPE_1351) ? mousedrv_get_x() : (neos_and_amiga_buttons & 1) ? 0xff : 0);
136
421
BYTE mouse_get_y(void)
138
return mousedrv_get_y();
423
return ((mouse_type == MOUSE_TYPE_1351) ? mousedrv_get_y() : 0xff);