|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
1.1.1.2 root 4: * joystick/mouse emulation
5: *
6: * Copyright 2001, 2002 Toni Wilen
7: *
8: * new fetures:
9: * - very configurable (and very complex to configure :)
10: * - supports multiple native input devices (joysticks and mice)
11: * - supports mapping joystick/mouse buttons to keys and vice versa
12: * - joystick mouse emulation (supports both ports)
13: * - supports parallel port joystick adapter
14: * - full cd32 pad support (supports both ports)
15: * - fully backward compatible with old joystick/mouse configuration
1.1 root 16: *
17: */
18:
1.1.1.2 root 19: //#define DONGLE_DEBUG
20:
1.1 root 21: #include "sysconfig.h"
22: #include "sysdeps.h"
23:
1.1.1.5 ! root 24: #include <ctype.h>
! 25:
1.1 root 26: #include "options.h"
27: #include "custom.h"
28: #include "xwin.h"
1.1.1.2 root 29: #include "drawing.h"
1.1 root 30: #include "memory.h"
1.1.1.2 root 31: #include "events.h"
1.1 root 32: #include "newcpu.h"
1.1.1.2 root 33: #include "uae.h"
1.1 root 34: #include "picasso96.h"
1.1.1.2 root 35: #include "debug.h"
36: #include "gui.h"
37: #include "disk.h"
38: #include "audio.h"
1.1.1.4 root 39: #include "autoconf.h"
40: #include "traps.h"
41: #include "keyboard.h"
42: #include "inputdevice.h"
43: #include "keybuf.h"
1.1.1.2 root 44: #include "savestate.h"
45:
46: #define DIR_LEFT 1
47: #define DIR_RIGHT 2
48: #define DIR_UP 4
49: #define DIR_DOWN 8
50:
51: struct inputevent {
52: char *confname;
53: char *name;
54: int allow_mask;
55: int type;
56: int unit;
57: int data;
58: };
59:
60: #define JOYBUTTON_1 0 /* fire/left mousebutton */
61: #define JOYBUTTON_2 1 /* 2nd/right mousebutton */
62: #define JOYBUTTON_3 2 /* 3rd/middle mousebutton */
63: #define JOYBUTTON_CD32_PLAY 3
64: #define JOYBUTTON_CD32_RWD 4
65: #define JOYBUTTON_CD32_FFW 5
66: #define JOYBUTTON_CD32_GREEN 6
67: #define JOYBUTTON_CD32_YELLOW 7
68: #define JOYBUTTON_CD32_RED 8
69: #define JOYBUTTON_CD32_BLUE 9
70:
71: #define INPUTEVENT_JOY1_CD32_FIRST INPUTEVENT_JOY1_CD32_PLAY
72: #define INPUTEVENT_JOY2_CD32_FIRST INPUTEVENT_JOY2_CD32_PLAY
73: #define INPUTEVENT_JOY1_CD32_LAST INPUTEVENT_JOY1_CD32_BLUE
74: #define INPUTEVENT_JOY2_CD32_LAST INPUTEVENT_JOY2_CD32_BLUE
75:
76: /* event masks */
77: #define AM_KEY 1 /* keyboard allowed */
78: #define AM_JOY_BUT 2 /* joystick buttons allowed */
79: #define AM_JOY_AXIS 4 /* joystick axis allowed */
80: #define AM_MOUSE_BUT 8 /* mouse buttons allowed */
81: #define AM_MOUSE_AXIS 16 /* mouse direction allowed */
82: #define AM_AF 32 /* supports autofire */
83: #define AM_INFO 64 /* information data for gui */
84: #define AM_DUMMY 128 /* placeholder */
1.1.1.3 root 85: #define AM_AUTO 256 /* forces autofire */
1.1.1.2 root 86: #define AM_K (AM_KEY|AM_JOY_BUT|AM_MOUSE_BUT|AM_AF) /* generic button/switch */
87:
88: /* event flags */
89: #define ID_FLAG_AUTOFIRE 1
90:
91: #define DEFEVENT(A, B, C, D, E, F) {#A, B, C, D, E, F },
92: struct inputevent events[] = {
1.1.1.3 root 93: {0, 0, AM_K, 0, 0, 0},
1.1.1.2 root 94: #include "inputevents.def"
95: {0, 0, 0, 0, 0, 0}
96: };
97: #undef DEFEVENT
98:
99: static int sublevdir[2][MAX_INPUT_SUB_EVENT];
100:
101: struct uae_input_device2 {
102: uae_u32 buttonmask;
103: int states[MAX_INPUT_DEVICE_EVENTS / 2];
104: };
1.1 root 105:
1.1.1.2 root 106: static struct uae_input_device2 joysticks2[MAX_INPUT_DEVICES];
107: static struct uae_input_device2 mice2[MAX_INPUT_DEVICES];
1.1 root 108:
1.1.1.2 root 109: static uae_u8 mouse_settings_reset[MAX_INPUT_SETTINGS][MAX_INPUT_DEVICES];
110: static uae_u8 joystick_settings_reset[MAX_INPUT_SETTINGS][MAX_INPUT_DEVICES];
1.1 root 111:
1.1.1.3 root 112: static struct inputdevice_functions idev[3];
113:
1.1.1.2 root 114: static int isdevice (struct uae_input_device *id)
115: {
116: int i, j;
117: for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) {
118: for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) {
119: if (id->eventid[i][j] > 0)
120: return 1;
121: }
122: }
123: return 0;
124: }
1.1 root 125:
1.1.1.2 root 126: int inputdevice_uaelib (char *s, char *parm)
127: {
128: int i;
129:
130: for (i = 1; events[i].name; i++) {
131: if (!strcmp (s, events[i].confname)) {
132: handle_input_event (i, atol (parm), 1, 0);
133: return 1;
134: }
135: }
136: return 0;
137: }
138:
139: static struct uae_input_device *joysticks;
140: static struct uae_input_device *mice;
141: static struct uae_input_device *keyboards;
142: static struct uae_input_device_kbr_default *keyboard_default;
143:
144: static double mouse_axis[MAX_INPUT_DEVICES][MAX_INPUT_DEVICE_EVENTS];
145: static double oldm_axis[MAX_INPUT_DEVICES][MAX_INPUT_DEVICE_EVENTS];
146:
147: static int mouse_x[MAX_INPUT_DEVICES], mouse_y[MAX_INPUT_DEVICE_EVENTS];
148: static int mouse_delta[MAX_INPUT_DEVICES][MAX_INPUT_DEVICE_EVENTS];
149: static int mouse_deltanoreset[MAX_INPUT_DEVICES][MAX_INPUT_DEVICE_EVENTS];
150: static int joybutton[MAX_INPUT_DEVICES];
151: static unsigned int joydir[MAX_INPUT_DEVICE_EVENTS];
152: static int joydirpot[MAX_INPUT_DEVICE_EVENTS][2];
153: static int mouse_frame_x[2], mouse_frame_y[2];
154:
155: static int mouse_port[2];
156: static int cd32_shifter[2];
157: static int cd32_pad_enabled[2];
158: static int parport_joystick_enabled;
159: static int oldmx[4], oldmy[4];
160: static int oleft[4], oright[4], otop[4], obot[4];
161: static int potgo_hsync;
162:
163: static int use_joysticks[MAX_INPUT_DEVICES];
164: static int use_mice[MAX_INPUT_DEVICES];
165: static int use_keyboards[MAX_INPUT_DEVICES];
166:
167: #define INPUT_QUEUE_SIZE 16
168: struct input_queue_struct {
169: int event, storedstate, state, max, framecnt, nextframecnt;
170: };
171: static struct input_queue_struct input_queue[INPUT_QUEUE_SIZE];
172:
173: /* Sigh. */
174: #define cfgfile_write fprintf
175:
176: static void out_config (FILE *f, int id, int num, char *s1, char *s2)
177: {
178: cfgfile_write (f, "input.%d.%s%d=%s\n", id, s1, num, s2);
179: //write_log ("-input.%d.%s%d=%s\n", id, s1, num, s2);
180: }
181:
182: static void write_config2 (FILE *f, int idnum, int i, int offset, char *tmp1, struct uae_input_device *id)
183: {
184: char tmp2[200], *p;
185: int event, got, j, k;
186: char *custom;
187:
188: p = tmp2;
189: got = 0;
190: for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) {
191: event = id->eventid[i + offset][j];
192: custom = id->custom[i + offset][j];
193: if (custom == NULL && event <= 0) {
194: for (k = j + 1; k < MAX_INPUT_SUB_EVENT; k++) {
195: if (id->eventid[i + offset][k] > 0) break;
196: }
197: if (k == MAX_INPUT_SUB_EVENT)
198: break;
199: }
200: if (p > tmp2) {
201: *p++ = ',';
202: *p = 0;
203: }
204: if (custom)
205: sprintf (p, "'%s'.%d", custom, id->flags[i + offset][j]);
206: else if (event <= 0)
207: sprintf (p, "NULL");
208: else
209: sprintf (p, "%s.%d", events[event].confname, id->flags[i + offset][j]);
210: p += strlen (p);
211: }
212: if (p > tmp2)
213: out_config (f, idnum, i, tmp1, tmp2);
214: }
1.1 root 215:
1.1.1.2 root 216: static void write_config (FILE *f, int idnum, int devnum, char *name, struct uae_input_device *id, struct uae_input_device2 *id2)
217: {
218: char tmp1[100];
219: int i;
1.1 root 220:
1.1.1.2 root 221: if (!isdevice (id))
222: return;
223: cfgfile_write (f, "input.%d.%s.%d.disabled=%d\n", idnum, name, devnum, id->enabled ? 0 : 1);
224: sprintf (tmp1, "%s.%d.axis.", name, devnum);
225: for (i = 0; i < ID_AXIS_TOTAL; i++)
226: write_config2 (f, idnum, i, ID_AXIS_OFFSET, tmp1, id);
227: sprintf (tmp1, "%s.%d.button." ,name, devnum);
228: for (i = 0; i < ID_BUTTON_TOTAL; i++)
229: write_config2 (f, idnum, i, ID_BUTTON_OFFSET, tmp1, id);
230: }
1.1 root 231:
1.1.1.2 root 232: static void kbrlabel (char *s)
233: {
234: while (*s) {
235: *s = toupper(*s);
236: if (*s == ' ') *s = '_';
237: s++;
238: }
239: }
1.1 root 240:
1.1.1.2 root 241: static void write_kbr_config (FILE *f, int idnum, int devnum, struct uae_input_device *kbr)
1.1 root 242: {
1.1.1.2 root 243: char tmp1[200], tmp2[200], tmp3[200], *p;
244: int i, j, k, event, skip;
245:
246: if (!keyboard_default)
1.1 root 247: return;
1.1.1.2 root 248: i = 0;
249: while (i < MAX_INPUT_DEVICE_EVENTS && kbr->extra[i][0] >= 0) {
250: skip = 0;
251: k = 0;
252: while (keyboard_default[k].scancode >= 0) {
253: if (keyboard_default[k].scancode == kbr->extra[i][0]) {
254: skip = 1;
255: for (j = 1; j < MAX_INPUT_SUB_EVENT; j++) {
256: if (kbr->flags[i][j] || kbr->eventid[i][j] > 0)
257: skip = 0;
258: }
259: if (keyboard_default[k].event != kbr->eventid[i][0] || kbr->flags[i][0] != 0)
260: skip = 0;
261: break;
262: }
263: k++;
264: }
265: if (kbr->eventid[i][0] == 0 && kbr->flags[i][0] == 0 && keyboard_default[k].scancode < 0)
266: skip = 1;
267: if (skip) {
268: i++;
269: continue;
270: }
271: p = tmp2;
272: p[0] = 0;
273: for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) {
274: char *custom = kbr->custom[i][j];
275: event = kbr->eventid[i][j];
276: if (custom == NULL && event <= 0) {
277: for (k = j + 1; k < MAX_INPUT_SUB_EVENT; k++) {
278: if (kbr->eventid[i][k] > 0) break;
279: }
280: if (k == MAX_INPUT_SUB_EVENT)
281: break;
282: }
283: if (p > tmp2) {
284: *p++ = ',';
285: *p = 0;
286: }
287: if (custom)
288: sprintf (p, "'%s'.%d", custom, kbr->flags[i][j]);
289: else if (event > 0)
290: sprintf (p, "%s.%d", events[event].confname, kbr->flags[i][j]);
291: else
292: strcat (p, "NULL");
293: p += strlen(p);
294: }
295: sprintf (tmp3, "%d", kbr->extra[i][0]);
296: kbrlabel (tmp3);
297: sprintf (tmp1, "keyboard.%d.button.%s", devnum, tmp3);
298: cfgfile_write (f, "input.%d.%s=%s\n", idnum, tmp1, tmp2);
299: i++;
300: }
301: }
302:
303: void write_inputdevice_config (struct uae_prefs *p, FILE *f)
304: {
305: int i, id;
306:
307: cfgfile_write (f, "input.config=%d\n", p->input_selected_setting);
308: cfgfile_write (f, "input.joymouse_speed_analog=%d\n", p->input_joymouse_multiplier);
309: cfgfile_write (f, "input.joymouse_speed_digital=%d\n", p->input_joymouse_speed);
310: cfgfile_write (f, "input.joymouse_deadzone=%d\n", p->input_joymouse_deadzone);
311: cfgfile_write (f, "input.joystick_deadzone=%d\n", p->input_joystick_deadzone);
312: cfgfile_write (f, "input.mouse_speed=%d\n", p->input_mouse_speed);
313: cfgfile_write (f, "input.autofire=%d\n", p->input_autofire_framecnt);
314: for (id = 1; id <= MAX_INPUT_SETTINGS; id++) {
315: for (i = 0; i < MAX_INPUT_DEVICES; i++)
316: write_config (f, id, i, "joystick", &p->joystick_settings[id][i], &joysticks2[i]);
317: for (i = 0; i < MAX_INPUT_DEVICES; i++)
318: write_config (f, id, i, "mouse", &p->mouse_settings[id][i], &mice2[i]);
319: for (i = 0; i < MAX_INPUT_DEVICES; i++)
320: write_kbr_config (f, id, i, &p->keyboard_settings[id][i]);
321: }
322: }
323:
324: static int getnum (char **pp)
325: {
326: char *p = *pp;
327: int v = atol (p);
328:
1.1.1.3 root 329: while (*p != 0 && *p !='.' && *p != ',')
330: p++;
331: if (*p == '.' || *p == ',')
332: p++;
1.1.1.2 root 333: *pp = p;
334: return v;
335: }
336: static char *getstring (char **pp)
337: {
338: int i;
339: static char str[1000];
340: char *p = *pp;
341:
342: if (*p == 0)
343: return 0;
344: i = 0;
1.1.1.3 root 345: while (*p != 0 && *p !='.' && *p != ',')
346: str[i++] = *p++;
347: if (*p == '.' || *p == ',')
348: p++;
1.1.1.2 root 349: str[i] = 0;
350: *pp = p;
351: return str;
352: }
353:
354: void reset_inputdevice_config (struct uae_prefs *pr)
355: {
356: memset (joystick_settings_reset, 0, sizeof (joystick_settings_reset));
357: memset (mouse_settings_reset, 0, sizeof (mouse_settings_reset));
358: }
1.1 root 359:
1.1.1.2 root 360: static void clear_id (struct uae_input_device *id)
361: {
362: #ifndef _DEBUG
363: int i, j;
364: for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) {
365: for (j = 0; j < MAX_INPUT_SUB_EVENT; j++)
366: free (id->custom[i][j]);
367: }
368: #endif
369: memset (id, 0, sizeof (struct uae_input_device));
370: id->enabled = 1;
1.1 root 371: }
372:
1.1.1.2 root 373: void read_inputdevice_config (struct uae_prefs *pr, char *option, char *value)
1.1 root 374: {
1.1.1.2 root 375: struct uae_input_device *id = 0;
376: struct inputevent *ie;
377: int devnum, num, button, joystick, flags, i, subnum, idnum, keynum;
378: int mask;
379: char *p, *p2, *custom;
380:
381: option += 6; /* "input." */
382: p = getstring (&option);
383: if (!strcasecmp (p, "config"))
384: pr->input_selected_setting = atol (value);
385: if (!strcasecmp (p, "joymouse_speed_analog"))
386: pr->input_joymouse_multiplier = atol (value);
387: if (!strcasecmp (p, "joymouse_speed_digital"))
388: pr->input_joymouse_speed = atol (value);
389: if (!strcasecmp (p, "joystick_deadzone"))
390: pr->input_joystick_deadzone = atol (value);
391: if (!strcasecmp (p, "joymouse_deadzone"))
392: pr->input_joymouse_deadzone = atol (value);
393: if (!strcasecmp (p, "mouse_speed"))
394: pr->input_mouse_speed = atol (value);
395: if (!strcasecmp (p, "autofire"))
396: pr->input_autofire_framecnt = atol (value);
397: idnum = atol (p);
398: if (idnum <= 0 || idnum > MAX_INPUT_SETTINGS)
399: return;
400: if (memcmp (option, "mouse.", 6) == 0) {
401: p = option + 6;
402: devnum = getnum (&p);
403: if (devnum < 0 || devnum >= MAX_INPUT_DEVICES)
404: return;
405: id = &pr->mouse_settings[idnum][devnum];
406: if (!mouse_settings_reset[idnum][devnum])
407: clear_id (id);
408: mouse_settings_reset[idnum][devnum] = 1;
409: joystick = 0;
410: } else if (memcmp (option, "joystick.", 9) == 0) {
411: p = option + 9;
412: devnum = getnum (&p);
413: if (devnum < 0 || devnum >= MAX_INPUT_DEVICES)
414: return;
415: id = &pr->joystick_settings[idnum][devnum];
416: if (!joystick_settings_reset[idnum][devnum])
417: clear_id (id);
418: joystick_settings_reset[idnum][devnum] = 1;
419: joystick = 1;
420: } else if (memcmp (option, "keyboard.", 9) == 0) {
421: joystick = -1;
422: p = option + 9;
423: devnum = getnum (&p);
424: if (devnum < 0 || devnum >= MAX_INPUT_DEVICES)
425: return;
426: id = &pr->keyboard_settings[idnum][devnum];
427: }
428: if (!id)
429: return;
430: p2 = getstring (&p);
431: if (!p2)
1.1 root 432: return;
1.1.1.2 root 433: if (!strcmp (p2, "disabled")) {
434: int disabled;
435: p = value;
436: disabled = getnum (&p);
437: id->enabled = disabled == 0 ? 1 : 0;
438: return;
439: }
440:
441: if (joystick < 0) {
442: num = getnum (&p);
443: keynum = 0;
444: while (id->extra[keynum][0] >= 0) {
445: if (id->extra[keynum][0] == num)
446: break;
447: keynum++;
448: }
449: if (id->extra[keynum][0] < 0)
450: return;
451: } else {
452: button = -1;
453: if (!strcmp (p2, "axis"))
454: button = 0;
455: else if(!strcmp (p2, "button"))
456: button = 1;
457: if (button < 0)
458: return;
459: num = getnum (&p);
460: }
461: p = value;
462:
463: custom = NULL;
464: for (subnum = 0; subnum < MAX_INPUT_SUB_EVENT; subnum++) {
465: free (custom);
466: custom = NULL;
467: p2 = getstring (&p);
468: if (!p2)
469: break;
470: i = 1;
471: while (events[i].name) {
472: if (!strcmp (events[i].confname, p2))
473: break;
474: i++;
475: }
476: ie = &events[i];
477: if (!ie->name) {
478: ie = &events[0];
479: if (strlen (p2) > 2 && p2[0] == '\'' && p2[strlen (p2) - 1] == '\'') {
480: custom = my_strdup (p2 + 1);
481: custom[strlen (custom) - 1] = 0;
482: }
483: }
484: flags = getnum (&p);
485: if (custom == NULL && ie->name == NULL)
486: continue;
487: if (joystick < 0) {
488: if (!(ie->allow_mask & AM_K))
489: continue;
490: id->eventid[keynum][subnum] = ie - events;
491: id->flags[keynum][subnum] = flags;
492: free (id->custom[keynum][subnum]);
493: id->custom[keynum][subnum] = custom;
494: } else if (button) {
495: if (joystick)
496: mask = AM_JOY_BUT;
497: else
498: mask = AM_MOUSE_BUT;
499: if (!(ie->allow_mask & mask))
500: continue;
501: id->eventid[num + ID_BUTTON_OFFSET][subnum] = ie - events;
502: id->flags[num + ID_BUTTON_OFFSET][subnum] = flags;
503: free (id->custom[num + ID_BUTTON_OFFSET][subnum]);
504: id->custom[num + ID_BUTTON_OFFSET][subnum] = custom;
505: } else {
506: if (joystick)
507: mask = AM_JOY_AXIS;
508: else
509: mask = AM_MOUSE_AXIS;
510: if (!(ie->allow_mask & mask))
511: continue;
512: id->eventid[num + ID_AXIS_OFFSET][subnum] = ie - events;
513: id->flags[num + ID_AXIS_OFFSET][subnum] = flags;
514: free (id->custom[num + ID_AXIS_OFFSET][subnum]);
515: id->custom[num + ID_AXIS_OFFSET][subnum] = custom;
516: }
517: custom = NULL;
518: }
519: free (custom);
520: }
521:
522: /* Mousehack stuff */
1.1 root 523:
1.1.1.2 root 524: static int ievent_alive = 0;
525: static int lastmx, lastmy;
526:
1.1.1.4 root 527: static void mousehack_setpos (int mousexpos, int mouseypos)
528: {
529: uae_u8 *p;
530: if (!uae_boot_rom)
531: return;
532: p = rtarea + get_long (RTAREA_BASE + 40) + 12;
533: p[0] = mousexpos >> 8;
534: p[1] = mousexpos;
535: p[2] = mouseypos >> 8;
536: p[3] = mouseypos;
537: //write_log ("%dx%d\n", mousexpos, mouseypos);
538: }
539:
540: static void new_mousehack_helper (void)
541: {
542: int mousexpos, mouseypos;
543:
544: if (!mousehack_allowed ())
545: return;
546: #ifdef PICASSO96
547: if (picasso_on) {
548: mousexpos = lastmx - picasso96_state.XOffset;
549: mouseypos = lastmy - picasso96_state.YOffset;
550: } else
551: #endif
552: {
553: mouseypos = coord_native_to_amiga_y (lastmy) << 1;
554: mousexpos = coord_native_to_amiga_x (lastmx);
555: }
556: mousehack_setpos (mousexpos, mouseypos);
557: }
558:
1.1.1.2 root 559: int mousehack_alive (void)
560: {
561: return ievent_alive > 0;
1.1 root 562: }
563:
1.1.1.4 root 564: uae_u32 mousehack_helper (TrapContext *dummy)
1.1 root 565: {
566: int mousexpos, mouseypos;
567:
568: #ifdef PICASSO96
569: if (picasso_on) {
1.1.1.2 root 570: mousexpos = lastmx - picasso96_state.XOffset;
571: mouseypos = lastmy - picasso96_state.YOffset;
1.1 root 572: } else
573: #endif
574: {
1.1.1.2 root 575: if (mouse_y[0] >= gfxvidinfo.height)
576: mouse_y[0] = gfxvidinfo.height - 1;
1.1 root 577: mouseypos = coord_native_to_amiga_y (lastmy) << 1;
578: mousexpos = coord_native_to_amiga_x (lastmx);
579: }
580:
581: switch (m68k_dreg (regs, 0)) {
582: case 0:
1.1.1.4 root 583: return ievent_alive ? -1 : (1 || !uae_boot_rom) && needmousehack ();
1.1 root 584: case 1:
585: ievent_alive = 10;
1.1.1.2 root 586: if (!mousehack_allowed ())
587: return 0;
1.1 root 588: return mousexpos;
589: case 2:
1.1.1.2 root 590: if (!mousehack_allowed ())
591: return 0;
1.1 root 592: return mouseypos;
593: }
594: return 0;
595: }
596:
597: STATIC_INLINE int adjust (int val)
598: {
599: if (val > 127)
600: return 127;
601: else if (val < -127)
602: return -127;
603: return val;
604: }
605:
1.1.1.2 root 606: int getbuttonstate (int joy, int button)
607: {
608: return joybutton[joy] & (1 << button);
609: }
610:
611: static void mouseupdate (int pct)
1.1 root 612: {
1.1.1.2 root 613: int v, i;
614:
615: for (i = 0; i < 2; i++) {
616:
617: v = mouse_delta[i][0] * pct / 100;
618: mouse_x[i] += v;
619: if (!mouse_deltanoreset[i][0])
620: mouse_delta[i][0] -= v;
621:
622: v = mouse_delta[i][1] * pct / 100;
623: mouse_y[i] += v;
624: if (!mouse_deltanoreset[i][1])
625: mouse_delta[i][1] -= v;
626:
627: v = mouse_delta[i][2] * pct / 100;
628: if (v > 0)
629: record_key (0x7a << 1);
630: else if (v < 0)
631: record_key (0x7b << 1);
632: if (!mouse_deltanoreset[i][2])
633: mouse_delta[i][2] = 0;
634:
635: if (mouse_frame_x[i] - mouse_x[i] > 127)
636: mouse_x[i] = mouse_frame_x[i] - 127;
637: if (mouse_frame_x[i] - mouse_x[i] < -127)
638: mouse_x[i] = mouse_frame_x[i] + 127;
639:
640: if (mouse_frame_y[i] - mouse_y[i] > 127)
641: mouse_y[i] = mouse_frame_y[i] - 127;
642: if (mouse_frame_y[i] - mouse_y[i] < -127)
643: mouse_y[i] = mouse_frame_y[i] + 127;
644:
645: if (pct == 100) {
646: if (!mouse_deltanoreset[i][0])
647: mouse_delta[i][0] = 0;
648: if (!mouse_deltanoreset[i][1])
649: mouse_delta[i][1] = 0;
650: if (!mouse_deltanoreset[i][2])
651: mouse_delta[i][2] = 0;
652: mouse_frame_x[i] = mouse_x[i];
653: mouse_frame_y[i] = mouse_y[i];
1.1 root 654: }
1.1.1.2 root 655:
656: }
657: }
658:
659: static int input_read, input_vpos;
660:
661: static void readinput (void)
662: {
663: if (!input_read && (vpos & ~31) != (input_vpos & ~31)) {
664: idev[IDTYPE_JOYSTICK].read ();
665: idev[IDTYPE_MOUSE].read ();
666: mouseupdate ((vpos - input_vpos) * 100 / maxvpos);
667: input_vpos = vpos;
668: }
669: if (input_read) {
670: input_vpos = vpos;
671: input_read = 0;
672: }
673: }
674:
675: int getjoystate (int joy)
676: {
677: int left = 0, right = 0, top = 0, bot = 0;
678: uae_u16 v = 0;
679:
680: readinput ();
681: if (joydir[joy] & DIR_LEFT)
682: left = 1;
683: if (joydir[joy] & DIR_RIGHT)
684: right = 1;
685: if (joydir[joy] & DIR_UP)
686: top = 1;
687: if (joydir[joy] & DIR_DOWN)
688: bot = 1;
689: v = (uae_u8)mouse_x[joy] | (mouse_y[joy] << 8);
690: if (left || right || top || bot || !mouse_port[joy]) {
691: if (left)
692: top = !top;
693: if (right)
694: bot = !bot;
695: v &= ~0x0303;
696: v |= bot | (right << 1) | (top << 8) | (left << 9);
697: }
698: #ifdef DONGLE_DEBUG
699: if (notinrom ())
700: write_log ("JOY%dDAT %04.4X %s\n", joy, v, debuginfo (0));
701: #endif
702: return v;
703: }
704:
705: uae_u16 JOY0DAT (void)
706: {
707: return getjoystate (0);
708: }
709: uae_u16 JOY1DAT (void)
710: {
711: return getjoystate (1);
712: }
713:
714: void JOYTEST (uae_u16 v)
715: {
716: mouse_x[0] &= 3;
717: mouse_y[0] &= 3;
718: mouse_x[1] &= 3;
719: mouse_y[1] &= 3;
720: mouse_x[0] |= v & 0xFC;
721: mouse_x[1] |= v & 0xFC;
722: mouse_y[0] |= (v >> 8) & 0xFC;
723: mouse_y[1] |= (v >> 8) & 0xFC;
724: mouse_frame_x[0] = mouse_x[0];
725: mouse_frame_y[0] = mouse_y[0];
726: mouse_frame_x[1] = mouse_x[1];
727: mouse_frame_y[1] = mouse_y[1];
1.1.1.4 root 728: // write_log ("%d:%04.4X %p\n",vpos,v,m68k_getpc ());
1.1.1.2 root 729: }
730:
731: static uae_u8 parconvert (uae_u8 v, int jd, int shift)
732: {
733: if (jd & DIR_UP)
734: v &= ~(1 << shift);
735: if (jd & DIR_DOWN)
736: v &= ~(2 << shift);
737: if (jd & DIR_LEFT)
738: v &= ~(4 << shift);
739: if (jd & DIR_RIGHT)
740: v &= ~(8 << shift);
741: return v;
742: }
743:
744:
745:
746: /* io-pins floating: dir=1 -> return data, dir=0 -> always return 1 */
747: uae_u8 handle_parport_joystick (int port, uae_u8 pra, uae_u8 dra)
748: {
749: uae_u8 v;
750: switch (port)
751: {
752: case 0:
753: v = (pra & dra) | (dra ^ 0xff);
754: if (parport_joystick_enabled) {
755: v = parconvert (v, joydir[2], 0);
756: v = parconvert (v, joydir[3], 4);
757: }
758: return v;
759: case 1:
760: v = ((pra & dra) | (dra ^ 0xff)) & 0x7;
761: if (parport_joystick_enabled) {
762: if (getbuttonstate (2, 0)) v &= ~1;
763: if (getbuttonstate (3, 0)) v &= ~4;
764: }
765: return v;
766: default:
1.1 root 767: abort ();
1.1.1.2 root 768: return 0;
1.1 root 769: }
770: }
771:
1.1.1.2 root 772: uae_u8 handle_joystick_buttons (uae_u8 dra)
1.1 root 773: {
1.1.1.2 root 774: uae_u8 but = 0;
775: int i;
776:
777: for (i = 0; i < 2; i++) {
778: if (cd32_pad_enabled[i]) {
779: uae_u16 p5dir = 0x0200 << (i * 4);
780: uae_u16 p5dat = 0x0100 << (i * 4);
781: but |= 0x40 << i;
782: /* Red button is connected to fire when p5 is 1 or floating */
783: if (!(potgo_value & p5dir) || ((potgo_value & p5dat) && (potgo_value & p5dir))) {
784: if (getbuttonstate (i, JOYBUTTON_CD32_RED))
785: but &= ~(0x40 << i);
786: }
787: } else if (!getbuttonstate (i, JOYBUTTON_1)) {
788: but |= 0x40 << i;
789: }
1.1 root 790: }
1.1.1.2 root 791: return but;
1.1 root 792: }
793:
1.1.1.2 root 794: /* joystick 1 button 1 is used as a output for incrementing shift register */
795: void handle_cd32_joystick_cia (uae_u8 pra, uae_u8 dra)
796: {
797: static int oldstate[2];
798: int i;
1.1 root 799:
1.1.1.2 root 800: for (i = 0; i < 2; i++) {
801: uae_u8 but = 0x40 << i;
802: uae_u16 p5dir = 0x0200 << (i * 4); /* output enable P5 */
803: uae_u16 p5dat = 0x0100 << (i * 4); /* data P5 */
804: if (!(potgo_value & p5dir) || !(potgo_value & p5dat)) {
805: if ((dra & but) && (pra & but) != oldstate[i]) {
806: if (!(pra & but)) {
807: cd32_shifter[i]--;
808: if (cd32_shifter[i] < 0)
809: cd32_shifter[i] = 0;
810: }
811: }
812: }
813: oldstate[i] = pra & but;
814: }
815: }
816:
817: /* joystick port 1 button 2 is input for button state */
818: static uae_u16 handle_joystick_potgor (uae_u16 potgor)
1.1 root 819: {
1.1.1.2 root 820: int i;
821:
822: for (i = 0; i < 2; i++) {
823: uae_u16 p9dir = 0x0800 << (i * 4); /* output enable P9 */
824: uae_u16 p9dat = 0x0400 << (i * 4); /* data P9 */
825: uae_u16 p5dir = 0x0200 << (i * 4); /* output enable P5 */
826: uae_u16 p5dat = 0x0100 << (i * 4); /* data P5 */
827:
828: if (mouse_port[i]) {
829: /* mouse has pull-up resistors in button lines */
830: if (!(potgo_value & p5dir))
831: potgor |= p5dat;
832: if (!(potgo_value & p9dir))
833: potgor |= p9dat;
834: }
835: if (potgo_hsync < 0) {
836: /* first 10 or so lines after potgo has started
837: * forces input-lines to zero
838: */
839: if (!(potgo_value & p5dir))
840: potgor &= ~p5dat;
841: if (!(potgo_value & p9dir))
842: potgor &= ~p9dat;
843: }
844:
845: if (cd32_pad_enabled[i]) {
846: /* p5 is floating in input-mode */
847: potgor &= ~p5dat;
848: potgor |= potgo_value & p5dat;
849: if (!(potgo_value & p9dir))
850: potgor |= p9dat;
851: /* P5 output and 1 -> shift register is kept reset (Blue button) */
852: if ((potgo_value & p5dir) && (potgo_value & p5dat))
853: cd32_shifter[i] = 8;
854: /* shift at 1 == return one, >1 = return button states */
855: if (cd32_shifter[i] == 0)
856: potgor &= ~p9dat; /* shift at zero == return zero */
857: if (cd32_shifter[i] >= 2 && (joybutton[i] & ((1 << JOYBUTTON_CD32_PLAY) << (cd32_shifter[i] - 2))))
858: potgor &= ~p9dat;
1.1.1.4 root 859: //write_log ("%d:%04.4X %08.8X\n", cd32_shifter[i], potgor, m68k_getpc ());
1.1.1.2 root 860: } else {
861: if (getbuttonstate (i, JOYBUTTON_3))
862: potgor &= ~p5dat;
863: if (getbuttonstate (i, JOYBUTTON_2))
864: potgor &= ~p9dat;
865: }
866: }
867: return potgor;
1.1 root 868: }
869:
1.1.1.2 root 870: uae_u16 potgo_value;
871: static uae_u16 potdats[2];
872: static int inputdelay;
873:
874: void inputdevice_hsync (void)
1.1 root 875: {
1.1.1.2 root 876: int joy;
1.1 root 877:
1.1.1.2 root 878: for (joy = 0; joy < 2; joy++) {
879: if (potgo_hsync >= 0) {
880: int active;
881:
882: active = 0;
883: if ((potgo_value >> 9) & 1) /* output? */
884: active = ((potgo_value >> 8) & 1) ? 0 : 1;
885: if (potgo_hsync < joydirpot[joy][0])
886: active = 1;
887: if (getbuttonstate (joy, JOYBUTTON_3))
888: active = 1;
889: if (active)
890: potdats[joy] = ((potdats[joy] + 1) & 0xFF) | (potdats[joy] & 0xFF00);
891:
892: active = 0;
893: if ((potgo_value >> 11) & 1) /* output? */
894: active = ((potgo_value >> 10) & 1) ? 0 : 1;
895: if (potgo_hsync < joydirpot[joy][1])
896: active = 1;
897: if (getbuttonstate (joy, JOYBUTTON_2))
898: active = 1;
899: if (active)
900: potdats[joy] += 0x100;
901: }
902: }
903: potgo_hsync++;
904: if (potgo_hsync > 255)
905: potgo_hsync = 255;
1.1 root 906:
907:
1.1.1.2 root 908: #ifdef CATWEASEL
909: catweasel_hsync ();
910: #endif
911: if (inputdelay > 0) {
912: inputdelay--;
913: if (inputdelay == 0) {
914: idev[IDTYPE_JOYSTICK].read ();
915: idev[IDTYPE_KEYBOARD].read ();
916: }
1.1 root 917: }
1.1.1.2 root 918: }
919:
920: uae_u16 POT0DAT (void)
921: {
922: return potdats[0];
923: }
924: uae_u16 POT1DAT (void)
925: {
926: return potdats[1];
927: }
928:
929: /* direction=input, data pin floating, last connected logic level or previous status
930: written when direction was ouput
931: * otherwise it is currently connected logic level.
932: * direction=output, data pin is current value, forced to zero if joystick button is pressed
933: * it takes some tens of microseconds before data pin changes state
934: */
935:
936: void POTGO (uae_u16 v)
937: {
938: int i;
1.1 root 939:
1.1.1.4 root 940: //write_log ("W:%d: %04.4X %p\n", vpos, v, m68k_getpc ());
1.1.1.2 root 941: #ifdef DONGLE_DEBUG
942: if (notinrom ())
943: write_log ("POTGO %04.4X %s\n", v, debuginfo(0));
944: #endif
945: potgo_value = potgo_value & 0x5500; /* keep state of data bits */
946: potgo_value |= v & 0xaa00; /* get new direction bits */
947: for (i = 0; i < 8; i += 2) {
948: uae_u16 dir = 0x0200 << i;
949: if (v & dir) {
950: uae_u16 data = 0x0100 << i;
951: potgo_value &= ~data;
952: potgo_value |= v & data;
953: }
954: }
955: for (i = 0; i < 2; i++) {
956: if (cd32_pad_enabled[i]) {
957: uae_u16 p5dir = 0x0200 << (i * 4); /* output enable P5 */
958: uae_u16 p5dat = 0x0100 << (i * 4); /* data P5 */
959: if ((potgo_value & p5dir) && (potgo_value & p5dat))
960: cd32_shifter[i] = 8;
961: }
962: }
963: if (v & 1) {
964: potdats[0] = potdats[1] = 0;
965: potgo_hsync = -15;
1.1 root 966: }
1.1.1.2 root 967: }
1.1 root 968:
1.1.1.2 root 969: uae_u16 POTGOR (void)
970: {
971: uae_u16 v = handle_joystick_potgor (potgo_value) & 0x5500;
1.1.1.4 root 972: //write_log ("R:%d:%04.4X %d %p\n", vpos, v, cd32_shifter[1], m68k_getpc ());
1.1 root 973: return v;
974: }
975:
1.1.1.2 root 976: static int check_input_queue (int event)
1.1 root 977: {
1.1.1.2 root 978: struct input_queue_struct *iq;
979: int i;
980: for (i = 0; i < INPUT_QUEUE_SIZE; i++) {
981: iq = &input_queue[i];
982: if (iq->event == event) return i;
1.1 root 983: }
1.1.1.2 root 984: return -1;
985: }
986:
987: static void queue_input_event (int event, int state, int max, int framecnt, int autofire)
988: {
989: struct input_queue_struct *iq;
990: int i = check_input_queue (event);
1.1 root 991:
1.1.1.2 root 992: if (event <= 0)
993: return;
994: if (state < 0 && i >= 0) {
995: iq = &input_queue[i];
996: iq->nextframecnt = -1;
997: iq->framecnt = -1;
998: iq->event = 0;
999: if (iq->state == 0)
1000: handle_input_event (event, 0, 1, 0);
1001: } else if (i < 0) {
1002: for (i = 0; i < INPUT_QUEUE_SIZE; i++) {
1003: iq = &input_queue[i];
1004: if (iq->framecnt < 0) break;
1005: }
1006: if (i == INPUT_QUEUE_SIZE) {
1007: write_log ("input queue overflow\n");
1008: return;
1009: }
1010: iq->event = event;
1011: iq->state = iq->storedstate = state;
1012: iq->max = max;
1013: iq->framecnt = framecnt;
1014: iq->nextframecnt = autofire > 0 ? framecnt : -1;
1015: }
1.1 root 1016: }
1.1.1.2 root 1017:
1018: static uae_u8 keybuf[256];
1019: static int inputcode_pending, inputcode_pending_state;
1020:
1021: /* Generate key up events for any keys that are 'stuck' down */
1022: void inputdevice_release_all_keys (void)
1.1 root 1023: {
1.1.1.2 root 1024: int i;
1025:
1026: for (i = 0; i < 0x80; i++) {
1027: if (keybuf[i] != 0) {
1028: keybuf[i] = 0;
1029: record_key (i << 1|1);
1030: }
1.1 root 1031: }
1032: }
1.1.1.2 root 1033:
1034: void inputdevice_add_inputcode (int code, int state)
1.1 root 1035: {
1.1.1.2 root 1036: inputcode_pending = code;
1037: inputcode_pending_state = state;
1038: }
1039:
1040: void inputdevice_do_keyboard (int code, int state)
1041: {
1042: if (code < 0x80) {
1043: uae_u8 key = code | (state ? 0x00 : 0x80);
1044: keybuf[key & 0x7f] = (key & 0x80) ? 0 : 1;
1045: if (((keybuf[AK_CTRL] || keybuf[AK_RCTRL]) && keybuf[AK_LAMI] && keybuf[AK_RAMI]) || key == AK_RESETWARNING) {
1046: int r = keybuf[AK_LALT] | keybuf[AK_RALT];
1047: memset (keybuf, 0, sizeof (keybuf));
1048: uae_reset (r);
1049: }
1050: record_key ((uae_u8)((key << 1) | (key >> 7)));
1.1.1.4 root 1051: //write_log ("Amiga key %02.2X %d\n", key & 0x7f, key >> 7);
1.1.1.2 root 1052: return;
1.1 root 1053: }
1.1.1.2 root 1054: inputdevice_add_inputcode (code, state);
1.1 root 1055: }
1.1.1.2 root 1056:
1057: void inputdevice_handle_inputcode (void)
1.1 root 1058: {
1.1.1.2 root 1059: int code = inputcode_pending;
1060: int state = inputcode_pending_state;
1061: inputcode_pending = 0;
1062: if (code == 0)
1063: return;
1064: if (vpos != 0)
1065: write_log ("inputcode=%d but vpos = %d", code, vpos);
1066:
1067: #ifdef ARCADIA
1068: switch (code)
1069: {
1070: case AKS_ARCADIADIAGNOSTICS:
1071: arcadia_flag &= ~1;
1072: arcadia_flag |= state ? 1 : 0;
1073: break;
1074: case AKS_ARCADIAPLY1:
1075: arcadia_flag &= ~4;
1076: arcadia_flag |= state ? 4 : 0;
1077: break;
1078: case AKS_ARCADIAPLY2:
1079: arcadia_flag &= ~2;
1080: arcadia_flag |= state ? 2 : 0;
1081: break;
1082: case AKS_ARCADIACOIN1:
1083: if (state)
1084: arcadia_coin[0]++;
1085: break;
1086: case AKS_ARCADIACOIN2:
1087: if (state)
1088: arcadia_coin[1]++;
1089: break;
1090: }
1091: #endif
1092:
1093: if (!state)
1094: return;
1095: switch (code)
1096: {
1097: case AKS_ENTERGUI:
1098: gui_display (-1);
1099: break;
1100: #if 0
1101: case AKS_SCREENSHOT:
1102: screenshot(1, 1);
1103: break;
1104: #endif
1105: #ifdef ACTION_REPLAY
1106: case AKS_FREEZEBUTTON:
1107: action_replay_freeze ();
1108: break;
1109: #endif
1110: case AKS_FLOPPY0:
1111: gui_display (0);
1112: break;
1113: case AKS_FLOPPY1:
1114: gui_display (1);
1115: break;
1116: case AKS_FLOPPY2:
1117: gui_display (2);
1118: break;
1119: case AKS_FLOPPY3:
1120: gui_display (3);
1121: break;
1122: case AKS_EFLOPPY0:
1123: disk_eject (0);
1124: break;
1125: case AKS_EFLOPPY1:
1126: disk_eject (1);
1127: break;
1128: case AKS_EFLOPPY2:
1129: disk_eject (2);
1130: break;
1131: case AKS_EFLOPPY3:
1132: disk_eject (3);
1133: break;
1134: #if 0
1135: case AKS_IRQ7:
1136: Interrupt (7);
1137: break;
1138: #endif
1139: case AKS_PAUSE:
1140: pausemode (-1);
1141: break;
1142: #if 0
1143: case AKS_WARP:
1144: warpmode (-1);
1145: break;
1146: #endif
1147: case AKS_INHIBITSCREEN:
1148: toggle_inhibit_frame (IHF_SCROLLLOCK);
1149: break;
1150: #if 0
1151: case AKS_STATEREWIND:
1152: savestate_dorewind(1);
1153: break;
1154: case AKS_VOLDOWN:
1155: sound_volume (-1);
1156: break;
1157: case AKS_VOLUP:
1158: sound_volume (1);
1159: break;
1160: case AKS_VOLMUTE:
1161: sound_volume (0);
1162: break;
1163: #endif
1164: case AKS_QUIT:
1165: uae_quit ();
1166: break;
1167: case AKS_SOFTRESET:
1168: uae_reset (0);
1169: break;
1170: case AKS_HARDRESET:
1171: uae_reset (1);
1172: break;
1173: #if 0
1174: case AKS_STATESAVEQUICK:
1175: case AKS_STATESAVEQUICK1:
1176: case AKS_STATESAVEQUICK2:
1177: case AKS_STATESAVEQUICK3:
1178: case AKS_STATESAVEQUICK4:
1179: case AKS_STATESAVEQUICK5:
1180: case AKS_STATESAVEQUICK6:
1181: case AKS_STATESAVEQUICK7:
1182: case AKS_STATESAVEQUICK8:
1183: case AKS_STATESAVEQUICK9:
1184: savestate_quick ((code - AKS_STATESAVEQUICK) / 2, 1);
1185: break;
1186: case AKS_STATERESTOREQUICK:
1187: case AKS_STATERESTOREQUICK1:
1188: case AKS_STATERESTOREQUICK2:
1189: case AKS_STATERESTOREQUICK3:
1190: case AKS_STATERESTOREQUICK4:
1191: case AKS_STATERESTOREQUICK5:
1192: case AKS_STATERESTOREQUICK6:
1193: case AKS_STATERESTOREQUICK7:
1194: case AKS_STATERESTOREQUICK8:
1195: case AKS_STATERESTOREQUICK9:
1196: savestate_quick ((code - AKS_STATERESTOREQUICK) / 2, 0);
1197: break;
1198: #endif
1199: case AKS_TOGGLEFULLSCREEN:
1200: toggle_fullscreen ();
1201: break;
1202: case AKS_TOGGLEMOUSEGRAB:
1203: toggle_mousegrab ();
1204: break;
1205: case AKS_ENTERDEBUGGER:
1206: activate_debugger ();
1207: break;
1208: case AKS_STATESAVEDIALOG:
1209: gui_display (5);
1210: break;
1211: case AKS_STATERESTOREDIALOG:
1212: gui_display (4);
1213: break;
1214: #if 0
1215: case AKS_DECREASEREFRESHRATE:
1216: case AKS_INCREASEREFRESHRATE:
1217: {
1218: int dir = code == AKS_INCREASEREFRESHRATE ? 5 : -5;
1219: if (currprefs.chipset_refreshrate == 0)
1220: currprefs.chipset_refreshrate = currprefs.ntscmode ? 60 : 50;
1221: changed_prefs.chipset_refreshrate = currprefs.chipset_refreshrate + dir;
1222: if (changed_prefs.chipset_refreshrate < 10)
1223: changed_prefs.chipset_refreshrate = 10;
1224: if (changed_prefs.chipset_refreshrate > 900)
1225: changed_prefs.chipset_refreshrate = 900;
1226: }
1227: break;
1228: #endif
1.1.1.3 root 1229: case AKS_SWITCHINTERPOL:
1230: switch_audio_interpol ();
1231: break;
1.1 root 1232: }
1233: }
1.1.1.2 root 1234:
1235: void handle_input_event (int nr, int state, int max, int autofire)
1236: {
1237: struct inputevent *ie;
1238: int joy;
1239:
1240: if (nr <= 0)
1241: return;
1242: ie = &events[nr];
1.1.1.4 root 1243: //write_log ("'%s' %d %d\n", ie->name, state, max);
1.1.1.2 root 1244: if (autofire) {
1245: if (state)
1246: queue_input_event (nr, state, max, currprefs.input_autofire_framecnt, 1);
1247: else
1248: queue_input_event (nr, -1, 0, 0, 1);
1249: }
1250: switch (ie->unit)
1251: {
1252: case 1: /* ->JOY1 */
1253: case 2: /* ->JOY2 */
1254: case 3: /* ->Parallel port joystick adapter port #1 */
1255: case 4: /* ->Parallel port joystick adapter port #2 */
1256: joy = ie->unit - 1;
1257: if (ie->type & 4) {
1258: if (state)
1259: joybutton[joy] |= 1 << ie->data;
1260: else
1261: joybutton[joy] &= ~(1 << ie->data);
1262: } else if (ie->type & 8) {
1263: /* real mouse / analog stick mouse emulation */
1264: int delta;
1265: int deadzone = currprefs.input_joymouse_deadzone * max / 100;
1266: if (max) {
1267: if (state < deadzone && state > -deadzone) {
1268: state = 0;
1269: } else if (state < 0) {
1270: state += deadzone;
1271: } else {
1272: state -= deadzone;
1273: }
1274: max -= deadzone;
1275: delta = state * currprefs.input_joymouse_multiplier / max;
1276: } else {
1277: delta = state;
1278: }
1279: mouse_delta[joy][ie->data] += delta;
1280: } else if (ie->type & 32) {
1281: int speed = currprefs.input_joymouse_speed;
1282:
1283: /* button mouse emulation */
1284: if (state && (ie->data & DIR_LEFT)) {
1285: mouse_delta[joy][0] = -speed;
1286: mouse_deltanoreset[joy][0] = 1;
1287: } else if (state && (ie->data & DIR_RIGHT)) {
1288: mouse_delta[joy][0] = speed;
1289: mouse_deltanoreset[joy][0] = 1;
1290: } else
1291: mouse_deltanoreset[joy][0] = 0;
1292:
1293: if (state && (ie->data & DIR_UP)) {
1294: mouse_delta[joy][1] = -speed;
1295: mouse_deltanoreset[joy][1] = 1;
1296: } else if (state && (ie->data & DIR_DOWN)) {
1297: mouse_delta[joy][1] = speed;
1298: mouse_deltanoreset[joy][1] = 1;
1299: } else
1300: mouse_deltanoreset[joy][1] = 0;
1301:
1302: } else if (ie->type & 64) { /* analog (paddle) */
1303: int deadzone = currprefs.input_joymouse_deadzone * max / 100;
1304: if (max) {
1305: if (state < deadzone && state > -deadzone) {
1306: state = 0;
1307: } else if (state < 0) {
1308: state += deadzone;
1309: } else {
1310: state -= deadzone;
1311: }
1312: state = state * max / (max - deadzone);
1313: }
1314: state = state / 256 + 128;
1315: joydirpot[joy][ie->data] = state;
1316: } else {
1317: int left = oleft[joy], right = oright[joy], top = otop[joy], bot = obot[joy];
1318: if (ie->type & 16) {
1319: /* button to axis mapping */
1320: if (ie->data & DIR_LEFT) left = oleft[joy] = state ? 1 : 0;
1321: if (ie->data & DIR_RIGHT) right = oright[joy] = state ? 1 : 0;
1322: if (ie->data & DIR_UP) top = otop[joy] = state ? 1 : 0;
1323: if (ie->data & DIR_DOWN) bot = obot[joy] = state ? 1 : 0;
1324: } else {
1325: /* "normal" joystick axis */
1326: int deadzone = currprefs.input_joystick_deadzone * max / 100;
1327: int neg, pos;
1328: if (state < deadzone && state > -deadzone)
1329: state = 0;
1330: neg = state < 0 ? 1 : 0;
1331: pos = state > 0 ? 1 : 0;
1332: if (ie->data & DIR_LEFT) left = oleft[joy] = neg;
1333: if (ie->data & DIR_RIGHT) right = oright[joy] = pos;
1334: if (ie->data & DIR_UP) top = otop[joy] = neg;
1335: if (ie->data & DIR_DOWN) bot = obot[joy] = pos;
1336: }
1337: joydir[joy] = 0;
1338: if (left) joydir[joy] |= DIR_LEFT;
1339: if (right) joydir[joy] |= DIR_RIGHT;
1340: if (top) joydir[joy] |= DIR_UP;
1341: if (bot) joydir[joy] |= DIR_DOWN;
1342: }
1343: break;
1344: case 0: /* ->KEY */
1345: inputdevice_do_keyboard (ie->data, state);
1346: break;
1347: }
1348: }
1349:
1350: void inputdevice_vsync (void)
1351: {
1352: struct input_queue_struct *iq;
1353: int i;
1354:
1355: for (i = 0; i < INPUT_QUEUE_SIZE; i++) {
1356: iq = &input_queue[i];
1357: if (iq->framecnt > 0) {
1358: iq->framecnt--;
1359: if (iq->framecnt == 0) {
1360: if (iq->state) iq->state = 0; else iq->state = iq->storedstate;
1361: handle_input_event (iq->event, iq->state, iq->max, 0);
1362: iq->framecnt = iq->nextframecnt;
1363: }
1364: }
1365: }
1366: mouseupdate (100);
1367: inputdelay = rand () % (maxvpos - 1);
1368: idev[IDTYPE_MOUSE].read ();
1369: input_read = 1;
1370: input_vpos = 0;
1371: inputdevice_handle_inputcode ();
1372: if (ievent_alive > 0)
1373: ievent_alive--;
1374: #ifdef ARCADIA
1375: if (arcadia_rom)
1376: arcadia_vsync ();
1377: #endif
1378: }
1379:
1380: void inputdevice_reset (void)
1381: {
1382: ievent_alive = 0;
1383: }
1384:
1385: static void setbuttonstateall (struct uae_input_device *id, struct uae_input_device2 *id2, int button, int state)
1386: {
1387: int event, autofire, i;
1388: uae_u32 mask = 1 << button;
1389: uae_u32 omask = id2->buttonmask & mask;
1390: uae_u32 nmask = (state ? 1 : 0) << button;
1391: char *custom;
1392:
1393: if (button >= ID_BUTTON_TOTAL)
1394: return;
1395: for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) {
1.1.1.3 root 1396: struct inputevent *ie;
1397:
1.1.1.2 root 1398: event = id->eventid[ID_BUTTON_OFFSET + button][sublevdir[state <= 0 ? 1 : 0][i]];
1399: custom = id->custom[ID_BUTTON_OFFSET + button][sublevdir[state <= 0 ? 1 : 0][i]];
1400: if (event <= 0 && custom == NULL)
1401: continue;
1402: autofire = (id->flags[ID_BUTTON_OFFSET + button][sublevdir[state <= 0 ? 1 : 0][i]] & ID_FLAG_AUTOFIRE) ? 1 : 0;
1.1.1.3 root 1403: ie = events + event;
1404: if (ie->allow_mask & AM_AUTO)
1405: autofire = 1;
1.1.1.2 root 1406: if (state < 0) {
1407: handle_input_event (event, 1, 1, 0);
1408: queue_input_event (event, 0, 1, 1, 0); /* send release event next frame */
1409: } else {
1410: if ((omask ^ nmask) & mask)
1411: handle_input_event (event, state, 1, autofire);
1412: }
1413: }
1414: if ((omask ^ nmask) & mask) {
1415: if (state)
1416: id2->buttonmask |= mask;
1417: else
1418: id2->buttonmask &= ~mask;
1419: }
1420: }
1421:
1422:
1423: /* - detect required number of joysticks and mice from configuration data
1424: * - detect if CD32 pad emulation is needed
1425: * - detect device type in ports (mouse or joystick)
1426: */
1427:
1428: static int iscd32 (int ei)
1429: {
1430: if (ei >= INPUTEVENT_JOY1_CD32_FIRST && ei <= INPUTEVENT_JOY1_CD32_LAST) {
1431: cd32_pad_enabled[0] = 1;
1432: return 1;
1433: }
1434: if (ei >= INPUTEVENT_JOY2_CD32_FIRST && ei <= INPUTEVENT_JOY2_CD32_LAST) {
1435: cd32_pad_enabled[1] = 1;
1436: return 2;
1437: }
1438: return 0;
1439: }
1440:
1441: static int isparport (int ei)
1442: {
1443: if (ei > INPUTEVENT_PAR_JOY1_START && ei < INPUTEVENT_PAR_JOY_END) {
1444: parport_joystick_enabled = 1;
1445: return 1;
1446: }
1447: return 0;
1448: }
1449:
1450: static int ismouse (int ei)
1451: {
1452: if (ei >= INPUTEVENT_MOUSE1_FIRST && ei <= INPUTEVENT_MOUSE1_LAST) {
1453: mouse_port[0] = 1;
1454: return 1;
1455: }
1456: if (ei >= INPUTEVENT_MOUSE2_FIRST && ei <= INPUTEVENT_MOUSE2_LAST) {
1457: mouse_port[1] = 1;
1458: return 2;
1459: }
1460: return 0;
1461: }
1462:
1463: #ifdef CD32
1464: extern int cd32_enabled;
1465: #endif
1466:
1.1.1.5 ! root 1467: static void scanevents (struct uae_prefs *p)
1.1.1.2 root 1468: {
1469: int i, j, k, ei;
1470: struct inputevent *e;
1471: int n_joy = idev[IDTYPE_JOYSTICK].get_num();
1472: int n_mouse = idev[IDTYPE_MOUSE].get_num();
1473:
1474: cd32_pad_enabled[0] = cd32_pad_enabled[1] = 0;
1475: parport_joystick_enabled = 0;
1476: mouse_port[0] = mouse_port[1] = 0;
1477: for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++)
1478: joydir[i] = 0;
1479:
1480: for (i = 0; i < MAX_INPUT_DEVICES; i++) {
1481: use_joysticks[i] = 0;
1482: use_mice[i] = 0;
1483: for (k = 0; k < MAX_INPUT_SUB_EVENT; k++) {
1484: for (j = 0; j < ID_BUTTON_TOTAL; j++) {
1485:
1486: if (joysticks[i].enabled && i < n_joy) {
1487: ei = joysticks[i].eventid[ID_BUTTON_OFFSET + j][k];
1488: e = &events[ei];
1489: iscd32 (ei);
1490: isparport (ei);
1491: ismouse (ei);
1492: if (joysticks[i].eventid[ID_BUTTON_OFFSET + j][k] > 0)
1493: use_joysticks[i] = 1;
1494: }
1495: if (mice[i].enabled && i < n_mouse) {
1496: ei = mice[i].eventid[ID_BUTTON_OFFSET + j][k];
1497: e = &events[ei];
1498: iscd32 (ei);
1499: isparport (ei);
1500: ismouse (ei);
1501: if (mice[i].eventid[ID_BUTTON_OFFSET + j][k] > 0)
1502: use_mice[i] = 1;
1503: }
1504:
1505: }
1506:
1507: for (j = 0; j < ID_AXIS_TOTAL; j++) {
1508:
1509: if (joysticks[i].enabled && i < n_joy) {
1510: ei = joysticks[i].eventid[ID_AXIS_OFFSET + j][k];
1511: iscd32 (ei);
1512: isparport (ei);
1513: ismouse (ei);
1514: if (ei > 0)
1515: use_joysticks[i] = 1;
1516: }
1517: if (mice[i].enabled && i < n_mouse) {
1518: ei = mice[i].eventid[ID_AXIS_OFFSET + j][k];
1519: iscd32 (ei);
1520: isparport (ei);
1521: ismouse (ei);
1522: if (ei > 0)
1523: use_mice[i] = 1;
1524: }
1525: }
1526: }
1527: }
1528: for (i = 0; i < MAX_INPUT_DEVICES; i++) {
1529: use_keyboards[i] = 0;
1530: if (keyboards[i].enabled && i < idev[IDTYPE_KEYBOARD].get_num()) {
1531: j = 0;
1532: while (keyboards[i].extra[j][0] >= 0) {
1533: use_keyboards[i] = 1;
1534: for (k = 0; k < MAX_INPUT_SUB_EVENT; k++) {
1535: ei = keyboards[i].eventid[j][k];
1536: iscd32 (ei);
1537: isparport (ei);
1538: ismouse (ei);
1539: }
1540: j++;
1541: }
1542: }
1543: }
1544: }
1545:
1546: #ifdef CD32
1547: static void setcd32 (int joy, int n)
1548: {
1549: joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = n ? INPUTEVENT_JOY2_CD32_RED : INPUTEVENT_JOY1_CD32_RED;
1550: joysticks[joy].eventid[ID_BUTTON_OFFSET + 1][0] = n ? INPUTEVENT_JOY2_CD32_BLUE : INPUTEVENT_JOY1_CD32_BLUE;
1551: joysticks[joy].eventid[ID_BUTTON_OFFSET + 2][0] = n ? INPUTEVENT_JOY2_CD32_YELLOW : INPUTEVENT_JOY1_CD32_YELLOW;
1552: joysticks[joy].eventid[ID_BUTTON_OFFSET + 3][0] = n ? INPUTEVENT_JOY2_CD32_GREEN : INPUTEVENT_JOY1_CD32_GREEN;
1553: joysticks[joy].eventid[ID_BUTTON_OFFSET + 4][0] = n ? INPUTEVENT_JOY2_CD32_FFW : INPUTEVENT_JOY1_CD32_FFW;
1554: joysticks[joy].eventid[ID_BUTTON_OFFSET + 5][0] = n ? INPUTEVENT_JOY2_CD32_RWD : INPUTEVENT_JOY1_CD32_RWD;
1555: joysticks[joy].eventid[ID_BUTTON_OFFSET + 6][0] = n ? INPUTEVENT_JOY2_CD32_PLAY : INPUTEVENT_JOY1_CD32_PLAY;
1556: }
1557: #endif
1558:
1559: int compatibility_device[2];
1560: static void compatibility_mode (struct uae_prefs *prefs)
1561: {
1562: int joy, i;
1563: int used[4] = { 0, 0, 0, 0};
1564:
1565: compatibility_device[0] = -1;
1566: compatibility_device[1] = -1;
1567: for (i = 0; i < MAX_INPUT_DEVICES; i++) {
1568: memset (&mice[i], 0, sizeof (*mice));
1569: memset (&joysticks[i], 0, sizeof (*joysticks));
1570: }
1571:
1572: if ((joy = jsem_ismouse (0, prefs)) >= 0) {
1573: mice[joy].eventid[ID_AXIS_OFFSET + 0][0] = INPUTEVENT_MOUSE1_HORIZ;
1574: mice[joy].eventid[ID_AXIS_OFFSET + 1][0] = INPUTEVENT_MOUSE1_VERT;
1575: mice[joy].eventid[ID_AXIS_OFFSET + 2][0] = INPUTEVENT_MOUSE1_WHEEL;
1576: mice[joy].eventid[ID_BUTTON_OFFSET + 0][0] = INPUTEVENT_JOY1_FIRE_BUTTON;
1577: mice[joy].eventid[ID_BUTTON_OFFSET + 1][0] = INPUTEVENT_JOY1_2ND_BUTTON;
1578: mice[joy].eventid[ID_BUTTON_OFFSET + 2][0] = INPUTEVENT_JOY1_3RD_BUTTON;
1579: mice[joy].eventid[ID_BUTTON_OFFSET + 3][0] = INPUTEVENT_KEY_ALT_LEFT;
1580: mice[joy].eventid[ID_BUTTON_OFFSET + 3][1] = INPUTEVENT_KEY_CURSOR_LEFT;
1581: mice[joy].eventid[ID_BUTTON_OFFSET + 4][0] = INPUTEVENT_KEY_ALT_LEFT;
1582: mice[joy].eventid[ID_BUTTON_OFFSET + 4][1] = INPUTEVENT_KEY_CURSOR_RIGHT;
1583: mice[joy].enabled = 1;
1584: }
1585: if ((joy = jsem_ismouse (1, prefs)) >= 0) {
1586: mice[joy].eventid[ID_AXIS_OFFSET + 0][0] = INPUTEVENT_MOUSE2_HORIZ;
1587: mice[joy].eventid[ID_AXIS_OFFSET + 1][0] = INPUTEVENT_MOUSE2_VERT;
1588: mice[joy].eventid[ID_BUTTON_OFFSET + 0][0] = INPUTEVENT_JOY2_FIRE_BUTTON;
1589: mice[joy].eventid[ID_BUTTON_OFFSET + 1][0] = INPUTEVENT_JOY2_2ND_BUTTON;
1590: mice[joy].eventid[ID_BUTTON_OFFSET + 2][0] = INPUTEVENT_JOY2_3RD_BUTTON;
1591: mice[joy].enabled = 1;
1592: }
1593:
1594: joy = jsem_isjoy (1, prefs);
1595: if (joy >= 0) {
1596: joysticks[joy].eventid[ID_AXIS_OFFSET + 0][0] = INPUTEVENT_JOY2_HORIZ;
1597: joysticks[joy].eventid[ID_AXIS_OFFSET + 1][0] = INPUTEVENT_JOY2_VERT;
1598: used[joy] = 1;
1599: joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = INPUTEVENT_JOY2_FIRE_BUTTON;
1600: joysticks[joy].eventid[ID_BUTTON_OFFSET + 1][0] = INPUTEVENT_JOY2_2ND_BUTTON;
1.1.1.3 root 1601: joysticks[joy].eventid[ID_BUTTON_OFFSET + 2][0] = INPUTEVENT_JOY2_FIRE_BUTTON_AF;
1.1.1.2 root 1602: #ifdef CD32
1603: if (cd32_enabled)
1604: setcd32 (joy, 1);
1605: #endif
1606: joysticks[joy].enabled = 1;
1607: }
1608:
1609: joy = jsem_isjoy (0, prefs);
1610: if (joy >= 0) {
1611: used[joy] = 1;
1612: joysticks[joy].eventid[ID_AXIS_OFFSET + 0][0] = INPUTEVENT_JOY1_HORIZ;
1613: joysticks[joy].eventid[ID_AXIS_OFFSET + 1][0] = INPUTEVENT_JOY1_VERT;
1614: joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = INPUTEVENT_JOY1_FIRE_BUTTON;
1615: joysticks[joy].eventid[ID_BUTTON_OFFSET + 1][0] = INPUTEVENT_JOY1_2ND_BUTTON;
1.1.1.3 root 1616: joysticks[joy].eventid[ID_BUTTON_OFFSET + 2][0] = INPUTEVENT_JOY1_FIRE_BUTTON_AF;
1.1.1.2 root 1617: joysticks[joy].enabled = 1;
1618: }
1619:
1620: for (joy = 0; used[joy]; joy++);
1621: if (JSEM_ISANYKBD (0, prefs)) {
1622: joysticks[joy].eventid[ID_AXIS_OFFSET + 0][0] = INPUTEVENT_JOY1_HORIZ;
1623: joysticks[joy].eventid[ID_AXIS_OFFSET + 1][0] = INPUTEVENT_JOY1_VERT;
1624: joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = INPUTEVENT_JOY1_FIRE_BUTTON;
1625: joysticks[joy].eventid[ID_BUTTON_OFFSET + 1][0] = INPUTEVENT_JOY1_2ND_BUTTON;
1626: joysticks[joy].eventid[ID_BUTTON_OFFSET + 2][0] = INPUTEVENT_JOY1_3RD_BUTTON;
1627: joysticks[joy].enabled = 1;
1628: used[joy] = 1;
1629: compatibility_device[0] = joy;
1630: }
1631: for (joy = 0; used[joy]; joy++);
1632: if (JSEM_ISANYKBD (1, prefs)) {
1633: joysticks[joy].eventid[ID_AXIS_OFFSET + 0][0] = INPUTEVENT_JOY2_HORIZ;
1634: joysticks[joy].eventid[ID_AXIS_OFFSET + 1][0] = INPUTEVENT_JOY2_VERT;
1635: joysticks[joy].eventid[ID_BUTTON_OFFSET + 0][0] = INPUTEVENT_JOY2_FIRE_BUTTON;
1636: joysticks[joy].eventid[ID_BUTTON_OFFSET + 1][0] = INPUTEVENT_JOY2_2ND_BUTTON;
1637: joysticks[joy].eventid[ID_BUTTON_OFFSET + 2][0] = INPUTEVENT_JOY2_3RD_BUTTON;
1638: #ifdef CD32
1639: if (cd32_enabled)
1640: setcd32 (joy, 1);
1641: #endif
1642: joysticks[joy].enabled = 1;
1643: used[joy] = 1;
1644: compatibility_device[1] = joy;
1645: }
1646: }
1647:
1648: void inputdevice_updateconfig (struct uae_prefs *prefs)
1649: {
1650: int i;
1651:
1652: if (currprefs.jport0 != changed_prefs.jport0
1653: || currprefs.jport1 != changed_prefs.jport1) {
1654: currprefs.jport0 = changed_prefs.jport0;
1655: currprefs.jport1 = changed_prefs.jport1;
1656: }
1657: joybutton[0] = joybutton[1] = 0;
1658: joydir[0] = joydir[1] = 0;
1659: oldmx[0] = oldmx[1] = -1;
1660: oldmy[0] = oldmy[1] = -1;
1661: cd32_shifter[0] = cd32_shifter[1] = 8;
1662: oleft[0] = oleft[1] = 0;
1663: oright[0] = oright[1] = 0;
1664: otop[0] = otop[1] = 0;
1665: obot[0] = obot[1] = 0;
1666: for (i = 0; i < 2; i++) {
1667: mouse_deltanoreset[i][0] = 0;
1668: mouse_delta[i][0] = 0;
1669: mouse_deltanoreset[i][1] = 0;
1670: mouse_delta[i][1] = 0;
1671: mouse_deltanoreset[i][2] = 0;
1672: mouse_delta[i][2] = 0;
1673: }
1674: memset (keybuf, 0, sizeof (keybuf));
1675:
1676: for (i = 0; i < INPUT_QUEUE_SIZE; i++)
1677: input_queue[i].framecnt = input_queue[i].nextframecnt = -1;
1678:
1679: for (i = 0; i < MAX_INPUT_SUB_EVENT; i++) {
1680: sublevdir[0][i] = i;
1681: sublevdir[1][i] = MAX_INPUT_SUB_EVENT - i - 1;
1682: }
1683:
1684: joysticks = prefs->joystick_settings[prefs->input_selected_setting];
1685: mice = prefs->mouse_settings[prefs->input_selected_setting];
1686: keyboards = prefs->keyboard_settings[prefs->input_selected_setting];
1687:
1688: memset (joysticks2, 0, sizeof (joysticks2));
1689: memset (mice2, 0, sizeof (mice2));
1690: if (prefs->input_selected_setting == 0)
1691: compatibility_mode (prefs);
1692:
1693: joystick_setting_changed ();
1694:
1695: scanevents (prefs);
1696:
1697: #ifdef CD32
1698: if (currprefs.input_selected_setting == 0 && cd32_enabled)
1699: cd32_pad_enabled[1] = 1;
1700: #endif
1701: }
1702:
1703: static void set_kbr_default (struct uae_prefs *p, int index, int num)
1704: {
1705: int i, j, k, l;
1706: struct uae_input_device_kbr_default *trans = keyboard_default;
1707: struct uae_input_device *kbr;
1708: struct inputdevice_functions *id = &idev[IDTYPE_KEYBOARD];
1709: uae_u32 scancode;
1710:
1711: if (!trans)
1712: return;
1713: for (j = 0; j < MAX_INPUT_DEVICES; j++) {
1714: kbr = &p->keyboard_settings[index][j];
1715: for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) {
1716: memset (kbr, 0, sizeof (struct uae_input_device));
1717: kbr->extra[i][0] = -1;
1718: }
1719: if (j < id->get_num ()) {
1720: if (j == 0)
1721: kbr->enabled = 1;
1722: for (i = 0; i < id->get_widget_num (num); i++) {
1723: id->get_widget_type (num, i, 0, &scancode);
1724: kbr->extra[i][0] = scancode;
1725: l = 0;
1726: while (trans[l].scancode >= 0) {
1727: if (kbr->extra[i][0] == trans[l].scancode) {
1728: for (k = 0; k < MAX_INPUT_SUB_EVENT; k++) {
1729: if (kbr->eventid[i][k] == 0) break;
1730: }
1731: if (k == MAX_INPUT_SUB_EVENT) {
1732: write_log ("corrupt default keyboard mappings\n");
1733: return;
1734: }
1735: kbr->eventid[i][k] = trans[l].event;
1736: break;
1737: }
1738: l++;
1739: }
1740: }
1741: }
1742: }
1743: }
1744:
1745: void inputdevice_default_prefs (struct uae_prefs *p)
1746: {
1747: int i;
1748:
1749: inputdevice_init ();
1750: p->input_joymouse_multiplier = 20;
1751: p->input_joymouse_deadzone = 33;
1752: p->input_joystick_deadzone = 33;
1753: p->input_joymouse_speed = 10;
1754: p->input_mouse_speed = 100;
1755: p->input_autofire_framecnt = 10;
1756: for (i = 0; i <= MAX_INPUT_SETTINGS; i++) {
1757: set_kbr_default (p, i, 0);
1758: input_get_default_mouse (p->mouse_settings[i]);
1759: input_get_default_joystick (p->joystick_settings[i]);
1760: }
1761: }
1762:
1763: void inputdevice_setkeytranslation (struct uae_input_device_kbr_default *trans)
1764: {
1765: keyboard_default = trans;
1766: }
1767:
1768: int inputdevice_translatekeycode (int keyboard, int scancode, int state)
1769: {
1770: struct uae_input_device *na = &keyboards[keyboard];
1771: int j, k;
1772:
1773: if (!keyboards || scancode < 0)
1774: return 0;
1775: j = 0;
1776: while (na->extra[j][0] >= 0) {
1777: if (na->extra[j][0] == scancode) {
1778: for (k = 0; k < MAX_INPUT_SUB_EVENT; k++) {/* send key release events in reverse order */
1779: int autofire = (na->flags[j][sublevdir[state == 0 ? 1 : 0][k]] & ID_FLAG_AUTOFIRE) ? 1 : 0;
1780: int event = na->eventid[j][sublevdir[state == 0 ? 1 : 0][k]];
1781: char *custom = na->custom[j][sublevdir[state == 0 ? 1 : 0][k]];
1782: handle_input_event (event, state, 1, autofire);
1783: //write_log ("'%s' %d ('%s') %d\n", na->name, event, events[event].name, state);
1784: }
1785: return 1;
1786: }
1787: j++;
1788: }
1789: return 0;
1790: }
1791:
1792: void inputdevice_init (void)
1793: {
1794: idev[IDTYPE_JOYSTICK] = inputdevicefunc_joystick;
1795: idev[IDTYPE_JOYSTICK].init ();
1796: idev[IDTYPE_MOUSE] = inputdevicefunc_mouse;
1797: idev[IDTYPE_MOUSE].init ();
1798: idev[IDTYPE_KEYBOARD] = inputdevicefunc_keyboard;
1799: idev[IDTYPE_KEYBOARD].init ();
1800: }
1801:
1802: void inputdevice_close (void)
1803: {
1804: idev[IDTYPE_JOYSTICK].close ();
1805: idev[IDTYPE_MOUSE].close ();
1806: idev[IDTYPE_KEYBOARD].close ();
1807: }
1808:
1809: static struct uae_input_device *get_uid (struct inputdevice_functions *id, int devnum)
1810: {
1811: struct uae_input_device *uid = 0;
1812: if (id == &idev[IDTYPE_JOYSTICK]) {
1813: uid = &joysticks[devnum];
1814: } else if (id == &idev[IDTYPE_MOUSE]) {
1815: uid = &mice[devnum];
1816: } else if (id == &idev[IDTYPE_KEYBOARD]) {
1817: uid = &keyboards[devnum];
1818: }
1819: return uid;
1820: }
1821:
1822: static int get_event_data (struct inputdevice_functions *id, int devnum, int num, int *eventid, char **custom, int *flags, int sub)
1823: {
1824: struct uae_input_device *uid = get_uid (id, devnum);
1825: int type = id->get_widget_type (devnum, num, 0, 0);
1826: int i;
1827: if (type == IDEV_WIDGET_BUTTON) {
1828: i = num - id->get_widget_first (devnum, type) + ID_BUTTON_OFFSET;
1829: *eventid = uid->eventid[i][sub];
1830: *flags = uid->flags[i][sub];
1831: *custom = uid->custom[i][sub];
1832: return i;
1833: } else if (type == IDEV_WIDGET_AXIS) {
1834: i = num - id->get_widget_first (devnum, type) + ID_AXIS_OFFSET;
1835: *eventid = uid->eventid[i][sub];
1836: *flags = uid->flags[i][sub];
1837: *custom = uid->custom[i][sub];
1838: return i;
1839: } else if (type == IDEV_WIDGET_KEY) {
1840: i = num - id->get_widget_first (devnum, type);
1841: *eventid = uid->eventid[i][sub];
1842: *flags = uid->flags[i][sub];
1843: *custom = uid->custom[i][sub];
1844: return i;
1845: }
1846: return -1;
1847: }
1848:
1849: static int put_event_data (struct inputdevice_functions *id, int devnum, int num, int eventid, char *custom, int flags, int sub)
1850: {
1851: struct uae_input_device *uid = get_uid (id, devnum);
1852: int type = id->get_widget_type (devnum, num, 0, 0);
1853: int i;
1854: if (type == IDEV_WIDGET_BUTTON) {
1855: i = num - id->get_widget_first (devnum, type) + ID_BUTTON_OFFSET;
1856: uid->eventid[i][sub] = eventid;
1857: uid->flags[i][sub] = flags;
1858: free (uid->custom[i][sub]);
1859: uid->custom[i][sub] = custom ? my_strdup (custom) : NULL;
1860: return i;
1861: } else if (type == IDEV_WIDGET_AXIS) {
1862: i = num - id->get_widget_first (devnum, type) + ID_AXIS_OFFSET;
1863: uid->eventid[i][sub] = eventid;
1864: uid->flags[i][sub] = flags;
1865: free (uid->custom[i][sub]);
1866: uid->custom[i][sub] = custom ? my_strdup (custom) : NULL;
1867: return i;
1868: } else if (type == IDEV_WIDGET_KEY) {
1869: i = num - id->get_widget_first (devnum, type);
1870: uid->eventid[i][sub] = eventid;
1871: uid->flags[i][sub] = flags;
1872: free (uid->custom[i][sub]);
1873: uid->custom[i][sub] = custom ? my_strdup (custom) : NULL;
1874: return i;
1875: }
1876: return -1;
1877: }
1878:
1879: static int is_event_used (struct inputdevice_functions *id, int devnum, int isnum, int isevent)
1880: {
1881: struct uae_input_device *uid = get_uid (id, devnum);
1882: int num, event, flag, sub;
1883: char *custom;
1884:
1885: for (num = 0; num < id->get_widget_num (devnum); num++) {
1886: for (sub = 0; sub < MAX_INPUT_SUB_EVENT; sub++) {
1887: if (get_event_data (id, devnum, num, &event, &custom, &flag, sub) >= 0) {
1888: if (event == isevent && isnum != num)
1889: return 1;
1890: }
1891: }
1892: }
1893: return 0;
1894: }
1895:
1896: int inputdevice_get_device_index (int devnum)
1897: {
1898: if (devnum < idev[IDTYPE_JOYSTICK].get_num())
1899: return devnum;
1900: else if (devnum < idev[IDTYPE_JOYSTICK].get_num() + idev[IDTYPE_MOUSE].get_num())
1901: return devnum - idev[IDTYPE_JOYSTICK].get_num();
1902: else if (devnum < idev[IDTYPE_JOYSTICK].get_num() + idev[IDTYPE_MOUSE].get_num() + idev[IDTYPE_KEYBOARD].get_num())
1903: return devnum - idev[IDTYPE_JOYSTICK].get_num() - idev[IDTYPE_MOUSE].get_num();
1904: else
1905: return -1;
1906: }
1907:
1908: static int gettype (int devnum)
1909: {
1910: if (devnum < idev[IDTYPE_JOYSTICK].get_num())
1911: return IDTYPE_JOYSTICK;
1912: else if (devnum < idev[IDTYPE_JOYSTICK].get_num() + idev[IDTYPE_MOUSE].get_num())
1913: return IDTYPE_MOUSE;
1914: else if (devnum < idev[IDTYPE_JOYSTICK].get_num() + idev[IDTYPE_MOUSE].get_num() + idev[IDTYPE_KEYBOARD].get_num())
1915: return IDTYPE_KEYBOARD;
1916: else
1917: return -1;
1918: }
1919:
1920: static struct inputdevice_functions *getidf (int devnum)
1921: {
1922: return &idev[gettype (devnum)];
1923: }
1924:
1925:
1926: /* returns number of devices of type "type" */
1927: int inputdevice_get_device_total (int type)
1928: {
1929: return idev[type].get_num ();
1930: }
1931: /* returns the name of device */
1932: char *inputdevice_get_device_name (int type, int devnum)
1933: {
1934: return idev[type].get_name (devnum);
1935: }
1936: /* returns state (enabled/disabled) */
1937: int inputdevice_get_device_status (int devnum)
1938: {
1939: struct inputdevice_functions *idf = getidf (devnum);
1940: struct uae_input_device *uid = get_uid (idf, inputdevice_get_device_index (devnum));
1941: return uid->enabled;
1942: }
1943:
1944: /* set state (enabled/disabled) */
1945: void inputdevice_set_device_status (int devnum, int enabled)
1946: {
1947: struct inputdevice_functions *idf = getidf (devnum);
1948: struct uae_input_device *uid = get_uid (idf, inputdevice_get_device_index (devnum));
1949: uid->enabled = enabled;
1950: }
1951:
1952: /* returns number of axis/buttons and keys from selected device */
1953: int inputdevice_get_widget_num (int devnum)
1954: {
1955: struct inputdevice_functions *idf = getidf (devnum);
1956: return idf->get_widget_num (inputdevice_get_device_index (devnum));
1957: }
1958:
1959: static void get_ename (struct inputevent *ie, char *out)
1960: {
1961: if (!out)
1962: return;
1963: if (ie->allow_mask == AM_K)
1964: sprintf (out, "%s (0x%02.2X)", ie->name, ie->data);
1965: else
1966: strcpy (out, ie->name);
1967: }
1968:
1969: int inputdevice_iterate (int devnum, int num, char *name, int *af)
1970: {
1971: struct inputdevice_functions *idf = getidf (devnum);
1972: static int id_iterator;
1973: struct inputevent *ie;
1974: int mask, data, flags, type;
1975: int devindex = inputdevice_get_device_index (devnum);
1976: char *custom;
1977:
1978: *af = 0;
1979: *name = 0;
1980: for (;;) {
1981: ie = &events[++id_iterator];
1982: if (!ie->confname) {
1983: id_iterator = 0;
1984: return 0;
1985: }
1986: mask = 0;
1987: type = idf->get_widget_type (devindex, num, 0, 0);
1988: if (type == IDEV_WIDGET_BUTTON) {
1989: if (idf == &idev[IDTYPE_JOYSTICK]) {
1990: mask |= AM_JOY_BUT;
1991: } else {
1992: mask |= AM_MOUSE_BUT;
1993: }
1994: } else if (type == IDEV_WIDGET_AXIS) {
1995: if (idf == &idev[IDTYPE_JOYSTICK]) {
1996: mask |= AM_JOY_AXIS;
1997: } else {
1998: mask |= AM_MOUSE_AXIS;
1999: }
2000: } else if (type == IDEV_WIDGET_KEY) {
2001: mask |= AM_K;
2002: }
2003: if (ie->allow_mask & AM_INFO) {
2004: struct inputevent *ie2 = ie + 1;
2005: while (!(ie2->allow_mask & AM_INFO)) {
2006: if (is_event_used (idf, devindex, ie2 - ie, -1)) {
2007: ie2++;
2008: continue;
2009: }
2010: if (ie2->allow_mask & mask) break;
2011: ie2++;
2012: }
2013: if (!(ie2->allow_mask & AM_INFO))
2014: mask |= AM_INFO;
2015: }
2016: if (!(ie->allow_mask & mask))
2017: continue;
2018: get_event_data (idf, devindex, num, &data, &custom, &flags, 0);
2019: get_ename (ie, name);
2020: *af = (flags & ID_FLAG_AUTOFIRE) ? 1 : 0;
2021: return 1;
2022: }
2023: }
2024:
2025: int inputdevice_get_mapped_name (int devnum, int num, int *pflags, char *name, char *custom, int sub)
2026: {
2027: struct inputdevice_functions *idf = getidf (devnum);
2028: struct uae_input_device *uid = get_uid (idf, inputdevice_get_device_index (devnum));
2029: int flags = 0, flag, data;
2030: int devindex = inputdevice_get_device_index (devnum);
2031: char *customp = NULL;
2032:
2033: if (name)
2034: strcpy (name, "<none>");
2035: if (custom)
2036: custom[0] = 0;
2037: if (pflags)
2038: *pflags = 0;
2039: if (uid == 0 || num < 0)
2040: return 0;
2041: if (get_event_data (idf, devindex, num, &data, &customp, &flag, sub) < 0)
2042: return 0;
2043: if (customp && custom)
2044: sprintf (custom, "\"%s\"", customp);
2045: if (flag & ID_FLAG_AUTOFIRE)
2046: flags |= IDEV_MAPPED_AUTOFIRE_SET;
2047: if (!data)
2048: return 0;
2049: if (events[data].allow_mask & AM_AF)
2050: flags |= IDEV_MAPPED_AUTOFIRE_POSSIBLE;
2051: if (pflags)
2052: *pflags = flags;
2053: get_ename (&events[data], name);
2054: return data;
2055: }
2056:
2057: int inputdevice_set_mapping (int devnum, int num, char *name, char *custom, int af, int sub)
2058: {
2059: struct inputdevice_functions *idf = getidf (devnum);
2060: struct uae_input_device *uid = get_uid (idf, inputdevice_get_device_index (devnum));
2061: int eid, data, flag, amask;
2062: char ename[256];
2063: int devindex = inputdevice_get_device_index (devnum);
2064:
2065: if (uid == 0 || num < 0)
2066: return 0;
2067: if (name) {
2068: eid = 1;
2069: while (events[eid].name) {
2070: get_ename (&events[eid], ename);
2071: if (!strcmp(ename, name)) break;
2072: eid++;
2073: }
2074: if (!events[eid].name)
2075: return 0;
2076: if (events[eid].allow_mask & AM_INFO)
2077: return 0;
2078: } else {
2079: eid = 0;
2080: }
2081: if (get_event_data (idf, devindex, num, &data, &custom, &flag, sub) < 0)
2082: return 0;
2083: if (data >= 0) {
2084: amask = events[eid].allow_mask;
2085: flag &= ~ID_FLAG_AUTOFIRE;
2086: if (amask & AM_AF)
2087: flag |= af ? ID_FLAG_AUTOFIRE : 0;
2088: put_event_data (idf, devindex, num, eid, custom, flag, sub);
2089: return 1;
2090: }
2091: return 0;
2092: }
2093:
2094: int inputdevice_get_widget_type (int devnum, int num, char *name)
2095: {
2096: struct inputdevice_functions *idf = getidf (devnum);
2097: return idf->get_widget_type (inputdevice_get_device_index (devnum), num, name, 0);
2098: }
2099:
2100: static int config_change;
2101:
2102: void inputdevice_config_change (void)
2103: {
2104: config_change = 1;
2105: }
2106:
2107: int inputdevice_config_change_test (void)
2108: {
2109: int v = config_change;
2110: config_change = 0;
2111: return v;
2112: }
2113:
2114: void inputdevice_copyconfig (struct uae_prefs *src, struct uae_prefs *dst)
2115: {
2116: int i, j;
2117:
2118: dst->input_selected_setting = src->input_selected_setting;
2119: dst->input_joymouse_multiplier = src->input_joymouse_multiplier;
2120: dst->input_joymouse_deadzone = src->input_joymouse_deadzone;
2121: dst->input_joystick_deadzone = src->input_joystick_deadzone;
2122: dst->input_joymouse_speed = src->input_joymouse_speed;
2123: dst->input_mouse_speed = src->input_mouse_speed;
2124: dst->input_autofire_framecnt = src->input_autofire_framecnt;
2125: dst->jport0 = src->jport0;
2126: dst->jport1 = src->jport1;
2127:
2128: for (i = 0; i < MAX_INPUT_SETTINGS + 1; i++) {
2129: for (j = 0; j < MAX_INPUT_DEVICES; j++) {
2130: memcpy (&dst->joystick_settings[i][j], &src->joystick_settings[i][j], sizeof (struct uae_input_device));
2131: memcpy (&dst->mouse_settings[i][j], &src->mouse_settings[i][j], sizeof (struct uae_input_device));
2132: memcpy (&dst->keyboard_settings[i][j], &src->keyboard_settings[i][j], sizeof (struct uae_input_device));
2133: }
2134: }
2135:
2136: inputdevice_updateconfig (dst);
2137: }
2138:
2139: void inputdevice_swap_ports (struct uae_prefs *p, int devnum)
2140: {
2141: struct inputdevice_functions *idf = getidf (devnum);
2142: struct uae_input_device *uid = get_uid (idf, inputdevice_get_device_index (devnum));
2143: int i, j, k, event, unit;
2144: struct inputevent *ie, *ie2;
2145:
2146: for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) {
2147: for (j = 0; j < MAX_INPUT_SUB_EVENT; j++) {
2148: event = uid->eventid[i][j];
2149: if (event <= 0)
2150: continue;
2151: ie = &events[event];
2152: if (ie->unit <= 0)
2153: continue;
2154: unit = ie->unit;
2155: k = 1;
2156: while (events[k].confname) {
2157: ie2 = &events[k];
2158: if (ie2->type == ie->type && ie2->data == ie->data && ie2->unit - 1 == ((ie->unit - 1) ^ 1) && ie2->allow_mask == ie->allow_mask) {
2159: uid->eventid[i][j] = k;
2160: break;
2161: }
2162: k++;
2163: }
2164: }
2165: }
2166: }
2167:
2168: void inputdevice_copy_single_config (struct uae_prefs *p, int src, int dst, int devnum)
2169: {
2170: if (src == dst)
2171: return;
2172: if (devnum < 0 || gettype (devnum) == IDTYPE_JOYSTICK)
2173: memcpy (p->joystick_settings[dst], p->joystick_settings[src], sizeof (struct uae_input_device) * MAX_INPUT_DEVICES);
2174: if (devnum < 0 || gettype (devnum) == IDTYPE_MOUSE)
2175: memcpy (p->mouse_settings[dst], p->mouse_settings[src], sizeof (struct uae_input_device) * MAX_INPUT_DEVICES);
2176: if (devnum < 0 || gettype (devnum) == IDTYPE_KEYBOARD)
2177: memcpy (p->keyboard_settings[dst], p->keyboard_settings[src], sizeof (struct uae_input_device) * MAX_INPUT_DEVICES);
2178: }
2179:
2180: void inputdevice_acquire (void)
2181: {
2182: int i;
2183:
2184: inputdevice_unacquire ();
2185: for (i = 0; i < MAX_INPUT_DEVICES; i++) {
2186: if (use_joysticks[i])
2187: idev[IDTYPE_JOYSTICK].acquire (i, 0);
2188: }
2189: for (i = 0; i < MAX_INPUT_DEVICES; i++) {
2190: if (use_mice[i])
2191: idev[IDTYPE_MOUSE].acquire (i, 0);
2192: }
2193: for (i = 0; i < MAX_INPUT_DEVICES; i++) {
2194: if (use_keyboards[i])
2195: idev[IDTYPE_KEYBOARD].acquire (i, 0);
2196: }
2197: }
2198:
2199: void inputdevice_unacquire (void)
2200: {
2201: int i;
2202:
2203: for (i = 0; i < MAX_INPUT_DEVICES; i++)
2204: idev[IDTYPE_JOYSTICK].unacquire (i);
2205: for (i = 0; i < MAX_INPUT_DEVICES; i++)
2206: idev[IDTYPE_MOUSE].unacquire (i);
2207: for (i = 0; i < MAX_INPUT_DEVICES; i++)
2208: idev[IDTYPE_KEYBOARD].unacquire (i);
2209: }
2210:
2211: /* Call this function when host machine's joystick/joypad/etc button state changes
2212: * This function translates button events to Amiga joybutton/joyaxis/keyboard events
2213: */
2214:
2215: /* button states:
2216: * state = -1 -> mouse wheel turned or similar (button without release)
2217: * state = 1 -> button pressed
2218: * state = 0 -> button released
2219: */
2220:
2221: void setjoybuttonstate (int joy, int button, int state)
2222: {
2223: if (!joysticks[joy].enabled)
2224: return;
2225: setbuttonstateall (&joysticks[joy], &joysticks2[joy], button, state ? 1 : 0);
2226: }
2227:
2228: /* buttonmask = 1 = normal toggle button, 0 = mouse wheel turn or similar
2229: */
2230: void setjoybuttonstateall (int joy, uae_u32 buttonbits, uae_u32 buttonmask)
2231: {
2232: int i;
2233:
2234: if (!joysticks[joy].enabled)
2235: return;
2236: for (i = 0; i < ID_BUTTON_TOTAL; i++) {
2237: if (buttonmask & (1 << i))
2238: setbuttonstateall (&joysticks[joy], &joysticks2[joy], i, (buttonbits & (1 << i)) ? 1 : 0);
2239: else if (buttonbits & (1 << i))
2240: setbuttonstateall (&joysticks[joy], &joysticks2[joy], i, -1);
2241: }
2242: }
2243: /* mouse buttons (just like joystick buttons)
2244: */
2245: void setmousebuttonstateall (int mouse, uae_u32 buttonbits, uae_u32 buttonmask)
2246: {
2247: int i;
2248:
2249: if (!mice[mouse].enabled)
2250: return;
2251: for (i = 0; i < ID_BUTTON_TOTAL; i++) {
2252: if (buttonmask & (1 << i))
2253: setbuttonstateall (&mice[mouse], &mice2[mouse], i, (buttonbits & (1 << i)) ? 1 : 0);
2254: else if (buttonbits & (1 << i))
2255: setbuttonstateall (&mice[mouse], &mice2[mouse], i, -1);
2256: }
2257: }
2258:
2259: void setmousebuttonstate (int mouse, int button, int state)
2260: {
2261: if (!mice[mouse].enabled)
2262: return;
2263: setbuttonstateall (&mice[mouse], &mice2[mouse], button, state);
2264: }
2265:
2266: /* same for joystick axis (analog or digital)
2267: * (0 = center, -max = full left/top, max = full right/bottom)
2268: */
2269: void setjoystickstate (int joy, int axis, int state, int max)
2270: {
2271: struct uae_input_device *id = &joysticks[joy];
2272: struct uae_input_device2 *id2 = &joysticks2[joy];
2273: int deadzone = currprefs.input_joymouse_deadzone * max / 100;
2274: int i, v1, v2;
2275:
2276: if (!joysticks[joy].enabled)
2277: return;
2278: v1 = state;
2279: v2 = id2->states[axis];
2280: if (v1 < deadzone && v1 > -deadzone)
2281: v1 = 0;
2282: if (v2 < deadzone && v2 > -deadzone)
2283: v2 = 0;
2284: if (v1 == v2)
2285: return;
2286: for (i = 0; i < MAX_INPUT_SUB_EVENT; i++)
2287: handle_input_event (id->eventid[ID_AXIS_OFFSET + axis][i], state, max,
2288: id->flags[ID_AXIS_OFFSET + axis][i]);
2289: id2->states[axis] = state;
2290: }
2291:
2292: void setmousestate (int mouse, int axis, int data, int isabs)
2293: {
2294: int i, v;
2295: double *mouse_p, *oldm_p, d, diff;
2296: struct uae_input_device *id = &mice[mouse];
2297: static double fract1[MAX_INPUT_DEVICES][MAX_INPUT_DEVICE_EVENTS];
2298: static double fract2[MAX_INPUT_DEVICES][MAX_INPUT_DEVICE_EVENTS];
2299:
2300: if (!mice[mouse].enabled)
2301: return;
2302: d = 0;
2303: mouse_p = &mouse_axis[mouse][axis];
2304: oldm_p = &oldm_axis[mouse][axis];
2305: if (!isabs) {
2306: *oldm_p = *mouse_p;
2307: *mouse_p += data;
2308: d = (*mouse_p - *oldm_p) * currprefs.input_mouse_speed / 100.0;
1.1.1.3 root 2309: /* printf (" offs %f\n", d); */
1.1.1.2 root 2310: } else {
2311: d = data - (int)(*oldm_p);
2312: *oldm_p = data;
2313: *mouse_p += d;
2314: if (axis == 0)
2315: lastmx = data;
2316: else
2317: lastmy = data;
2318: }
2319: v = (int)(d > 0 ? d + 0.5 : d - 0.5);
2320: fract1[mouse][axis] += d;
2321: fract2[mouse][axis] += v;
2322: diff = fract2[mouse][axis] - fract1[mouse][axis];
2323: if (diff > 1 || diff < -1) {
2324: v -= (int)diff;
2325: fract2[mouse][axis] -= diff;
2326: }
2327: for (i = 0; i < MAX_INPUT_SUB_EVENT; i++)
2328: handle_input_event (id->eventid[ID_AXIS_OFFSET + axis][i], v, 0, 0);
1.1.1.4 root 2329: new_mousehack_helper();
1.1.1.2 root 2330: }
2331:
2332: #if 0
2333: void warpmode (int mode)
2334: {
2335: if (mode < 0) {
2336: if (turbo_emulation) {
2337: changed_prefs.gfx_framerate = currprefs.gfx_framerate = turbo_emulation;
2338: turbo_emulation = 0;
2339: } else {
2340: turbo_emulation = currprefs.gfx_framerate;
2341: }
2342: } else if (mode == 0 && turbo_emulation > 0) {
2343: changed_prefs.gfx_framerate = currprefs.gfx_framerate = turbo_emulation;
2344: turbo_emulation = 0;
2345: } else if (mode > 0 && !turbo_emulation) {
2346: turbo_emulation = currprefs.gfx_framerate;
2347: }
2348: if (turbo_emulation) {
2349: #if 0
2350: if (!currprefs.cpu_cycle_exact && !currprefs.blitter_cycle_exact)
2351: changed_prefs.gfx_framerate = currprefs.gfx_framerate = 10;
2352: #endif
2353: pause_sound ();
2354: } else {
2355: resume_sound ();
2356: }
2357: compute_vsynctime ();
2358: }
2359: #endif
2360:
2361: void pausemode (int mode)
2362: {
2363: if (mode < 0)
2364: pause_emulation = pause_emulation ? 0 : 1;
2365: else
2366: pause_emulation = mode;
2367: }
2368:
2369: int jsem_isjoy (int port, struct uae_prefs *p)
2370: {
2371: int v = JSEM_DECODEVAL (port, p);
2372: if (v < JSEM_JOYS)
2373: return -1;
2374: v -= JSEM_JOYS;
2375: if (v >= inputdevice_get_device_total (IDTYPE_JOYSTICK))
2376: return -1;
2377: return v;
2378: }
2379: int jsem_ismouse (int port, struct uae_prefs *p)
2380: {
2381: int v = JSEM_DECODEVAL (port, p);
2382: if (v < JSEM_MICE)
2383: return -1;
2384: v -= JSEM_MICE;
2385: if (v >= inputdevice_get_device_total (IDTYPE_MOUSE))
2386: return -1;
2387: return v;
2388: }
2389: int jsem_iskbdjoy (int port, struct uae_prefs *p)
2390: {
2391: int v = JSEM_DECODEVAL (port, p);
2392: if (v < JSEM_KBDLAYOUT)
2393: return -1;
2394: v -= JSEM_KBDLAYOUT;
2395: if (v >= JSEM_LASTKBD)
2396: return -1;
2397: return v;
2398: }
2399:
2400: extern int jsem_ismouse (int v, struct uae_prefs*);
2401: extern int jsem_iskbd (int v, struct uae_prefs*);
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.