annotate io.c @ 1035:284d905ca582

Added support for binding a bunch more "special" keys
author Michael Pavone <pavone@retrodev.com>
date Mon, 16 May 2016 09:54:05 -0700
parents 56b1748a8473
children 1a66d5165ea7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
467
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 451
diff changeset
1 /*
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 451
diff changeset
2 Copyright 2013 Michael Pavone
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
3 This file is part of BlastEm.
467
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 451
diff changeset
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 451
diff changeset
5 */
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
6 #ifndef _WIN32
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
7 #include <unistd.h>
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
8 #include <fcntl.h>
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
9 #include <sys/socket.h>
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
10 #include <sys/un.h>
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
11 #include <sys/types.h>
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
12 #include <sys/stat.h>
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
13 #include <errno.h>
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
14 #endif
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
15 #include <string.h>
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
16 #include <stdlib.h>
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
17
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
18 #include "io.h"
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19 #include "blastem.h"
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
20 #include "render.h"
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
21 #include "util.h"
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
22
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
23 #define CYCLE_NEVER 0xFFFFFFFF
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
24
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
25 const char * device_type_names[] = {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
26 "3-button gamepad",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
27 "6-button gamepad",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
28 "Mega Mouse",
1026
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
29 "Saturn Keyboard",
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
30 "Menacer",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
31 "Justifier",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
32 "Sega multi-tap",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
33 "EA 4-way Play cable A",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
34 "EA 4-way Play cable B",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
35 "Sega Parallel Transfer Board",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
36 "Generic Device",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
37 "None"
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
38 };
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
39
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
40 enum {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
41 BIND_NONE,
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
42 BIND_UI,
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
43 BIND_GAMEPAD1,
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
44 BIND_GAMEPAD2,
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
45 BIND_GAMEPAD3,
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
46 BIND_GAMEPAD4,
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
47 BIND_GAMEPAD5,
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
48 BIND_GAMEPAD6,
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
49 BIND_GAMEPAD7,
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
50 BIND_GAMEPAD8,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
51 BIND_MOUSE1,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
52 BIND_MOUSE2,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
53 BIND_MOUSE3,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
54 BIND_MOUSE4,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
55 BIND_MOUSE5,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
56 BIND_MOUSE6,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
57 BIND_MOUSE7,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
58 BIND_MOUSE8
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
59 };
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
60
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
61 typedef enum {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
62 UI_DEBUG_MODE_INC,
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
63 UI_DEBUG_PAL_INC,
444
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
64 UI_ENTER_DEBUGGER,
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
65 UI_SAVE_STATE,
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
66 UI_SET_SPEED,
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
67 UI_NEXT_SPEED,
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
68 UI_PREV_SPEED,
916
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
69 UI_RELEASE_MOUSE,
444
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
70 UI_EXIT
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
71 } ui_action;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
72
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
73 typedef enum {
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
74 MOUSE_ABSOLUTE, //really only useful for menu ROM
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
75 MOUSE_RELATIVE, //for full screen
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
76 MOUSE_CAPTURE //for windowed mode
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
77 } mouse_modes;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
78
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
79
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
80 typedef struct {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
81 io_port *port;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
82 uint8_t bind_type;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
83 uint8_t subtype_a;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
84 uint8_t subtype_b;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
85 uint8_t value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
86 } keybinding;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
87
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
88 typedef struct {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
89 keybinding bindings[4];
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
90 uint8_t state;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
91 } joydpad;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
92
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
93 typedef struct {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
94 keybinding *buttons;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
95 joydpad *dpads;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
96 uint32_t num_buttons; //number of entries in the buttons array, not necessarily the number of buttons on the device
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
97 uint32_t num_dpads; //number of entries in the dpads array, not necessarily the number of dpads on the device
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
98 } joystick;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
99
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
100 typedef struct {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
101 io_port *motion_port;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
102 keybinding buttons[MAX_MOUSE_BUTTONS];
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
103 uint8_t bind_type;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
104 } mousebinding;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
105
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
106 #define DEFAULT_JOYBUTTON_ALLOC 12
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
107
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
108 static keybinding * bindings[0x10000];
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
109 static joystick joysticks[MAX_JOYSTICKS];
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
110 static mousebinding mice[MAX_MICE];
1026
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
111 static io_port *keyboard_port;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
112 const uint8_t dpadbits[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT};
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
113
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
114 void bind_key(int keycode, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
115 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
116 int bucket = keycode >> 15 & 0xFFFF;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
117 if (!bindings[bucket]) {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
118 bindings[bucket] = malloc(sizeof(keybinding) * 0x8000);
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
119 memset(bindings[bucket], 0, sizeof(keybinding) * 0x8000);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
120 }
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
121 int idx = keycode & 0x7FFF;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
122 bindings[bucket][idx].bind_type = bind_type;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
123 bindings[bucket][idx].subtype_a = subtype_a;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
124 bindings[bucket][idx].subtype_b = subtype_b;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
125 bindings[bucket][idx].value = value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
126 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
127
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
128 void bind_button(int joystick, int button, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
129 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
130 if (joystick >= MAX_JOYSTICKS) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
131 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
132 }
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
133 if (!joysticks[joystick].buttons) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
134 joysticks[joystick].num_buttons = button < DEFAULT_JOYBUTTON_ALLOC ? DEFAULT_JOYBUTTON_ALLOC : button + 1;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
135 joysticks[joystick].buttons = calloc(joysticks[joystick].num_buttons, sizeof(keybinding));
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
136 } else if (joysticks[joystick].num_buttons <= button) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
137 uint32_t old_capacity = joysticks[joystick].num_buttons;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
138 joysticks[joystick].num_buttons *= 2;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
139 joysticks[joystick].buttons = realloc(joysticks[joystick].buttons, sizeof(keybinding) * joysticks[joystick].num_buttons);
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
140 memset(joysticks[joystick].buttons + old_capacity, 0, joysticks[joystick].num_buttons - old_capacity);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
141 }
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
142 joysticks[joystick].buttons[button].bind_type = bind_type;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
143 joysticks[joystick].buttons[button].subtype_a = subtype_a;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
144 joysticks[joystick].buttons[button].subtype_b = subtype_b;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
145 joysticks[joystick].buttons[button].value = value;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
146 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
147
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
148 void bind_dpad(int joystick, int dpad, int direction, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
149 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
150 if (joystick >= MAX_JOYSTICKS) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
151 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
152 }
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
153 if (!joysticks[joystick].dpads) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
154 //multiple D-pads hats are not common, so don't allocate any extra space
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
155 joysticks[joystick].dpads = calloc(dpad+1, sizeof(joydpad));
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
156 joysticks[joystick].num_dpads = dpad+1;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
157 } else if (joysticks[joystick].num_dpads <= dpad) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
158 uint32_t old_capacity = joysticks[joystick].num_dpads;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
159 joysticks[joystick].num_dpads *= 2;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
160 joysticks[joystick].dpads = realloc(joysticks[joystick].dpads, sizeof(joydpad) * joysticks[joystick].num_dpads);
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
161 memset(joysticks[joystick].dpads + old_capacity, 0, joysticks[joystick].num_dpads - old_capacity);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
162 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
163 for (int i = 0; i < 4; i ++) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
164 if (dpadbits[i] & direction) {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
165 joysticks[joystick].dpads[dpad].bindings[i].bind_type = bind_type;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
166 joysticks[joystick].dpads[dpad].bindings[i].subtype_a = subtype_a;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
167 joysticks[joystick].dpads[dpad].bindings[i].subtype_b = subtype_b;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
168 joysticks[joystick].dpads[dpad].bindings[i].value = value;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
169 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
170 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
171 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
172 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
173
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
174 #define GAMEPAD_BUTTON(PRI_SLOT, SEC_SLOT, VALUE) (PRI_SLOT << 12 | SEC_SLOT << 8 | VALUE)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
175
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
176 #define DPAD_UP GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_TH1, 0x01)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
177 #define BUTTON_Z GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x01)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
178 #define DPAD_DOWN GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_TH1, 0x02)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
179 #define BUTTON_Y GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x02)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
180 #define DPAD_LEFT GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x04)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
181 #define BUTTON_X GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x04)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
182 #define DPAD_RIGHT GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x08)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
183 #define BUTTON_MODE GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x08)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
184 #define BUTTON_A GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_NONE, 0x10)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
185 #define BUTTON_B GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x10)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
186 #define BUTTON_START GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_NONE, 0x20)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
187 #define BUTTON_C GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x20)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
188
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
189 #define PSEUDO_BUTTON_MOTION 0xFFFF
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
190 #define MOUSE_LEFT 1
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
191 #define MOUSE_RIGHT 2
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
192 #define MOUSE_MIDDLE 4
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
193 #define MOUSE_START 8
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
194
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
195
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
196
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
197 void bind_gamepad(int keycode, int gamepadnum, int button)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
198 {
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
199
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
200 if (gamepadnum < 1 || gamepadnum > 8) {
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
201 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
202 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
203 uint8_t bind_type = gamepadnum - 1 + BIND_GAMEPAD1;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
204 bind_key(keycode, bind_type, button >> 12, button >> 8 & 0xF, button & 0xFF);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
205 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
206
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
207 void bind_button_gamepad(int joystick, int joybutton, int gamepadnum, int padbutton)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
208 {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
209 if (gamepadnum < 1 || gamepadnum > 8) {
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
210 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
211 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
212 uint8_t bind_type = gamepadnum - 1 + BIND_GAMEPAD1;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
213 bind_button(joystick, joybutton, bind_type, padbutton >> 12, padbutton >> 8 & 0xF, padbutton & 0xFF);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
214 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
215
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
216 void bind_dpad_gamepad(int joystick, int dpad, uint8_t direction, int gamepadnum, int button)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
217 {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
218 if (gamepadnum < 1 || gamepadnum > 8) {
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
219 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
220 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
221 uint8_t bind_type = gamepadnum - 1 + BIND_GAMEPAD1;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
222 bind_dpad(joystick, dpad, direction, bind_type, button >> 12, button >> 8 & 0xF, button & 0xFF);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
223 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
224
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
225 void bind_ui(int keycode, ui_action action, uint8_t param)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
226 {
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
227 bind_key(keycode, BIND_UI, action, 0, param);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
228 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
229
493
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
230 void bind_button_ui(int joystick, int joybutton, ui_action action, uint8_t param)
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
231 {
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
232 bind_button(joystick, joybutton, BIND_UI, action, 0, param);
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
233 }
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
234
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
235 void bind_dpad_ui(int joystick, int dpad, uint8_t direction, ui_action action, uint8_t param)
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
236 {
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
237 bind_dpad(joystick, dpad, direction, BIND_UI, action, 0, param);
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
238 }
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
239
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
240 void handle_binding_down(keybinding * binding)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
241 {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
242 if (binding->bind_type >= BIND_GAMEPAD1 && binding->bind_type <= BIND_GAMEPAD8)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
243 {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
244 if (binding->subtype_a <= GAMEPAD_EXTRA && binding->port) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
245 binding->port->input[binding->subtype_a] |= binding->value;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
246 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
247 if (binding->subtype_b <= GAMEPAD_EXTRA && binding->port) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
248 binding->port->input[binding->subtype_b] |= binding->value;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
249 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
250 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
251 else if (binding->bind_type >= BIND_MOUSE1 && binding->bind_type <= BIND_MOUSE8)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
252 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
253 if (binding->port) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
254 binding->port->input[0] |= binding->value;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
255 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
256 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
257 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
258
1026
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
259 void store_key_event(uint16_t code)
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
260 {
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
261 if (keyboard_port && keyboard_port->device.keyboard.write_pos != keyboard_port->device.keyboard.read_pos) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
262 //there's room in the buffer, record this event
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
263 keyboard_port->device.keyboard.events[keyboard_port->device.keyboard.write_pos] = code;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
264 if (keyboard_port->device.keyboard.read_pos == 0xFF) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
265 //ring buffer was empty, update read_pos to indicate there is now data
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
266 keyboard_port->device.keyboard.read_pos = keyboard_port->device.keyboard.write_pos;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
267 }
1026
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
268 keyboard_port->device.keyboard.write_pos = (keyboard_port->device.keyboard.write_pos + 1) & 7;
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
269 }
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
270 }
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
271
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
272 void handle_keydown(int keycode, uint8_t scancode)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
273 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
274 int bucket = keycode >> 15 & 0xFFFF;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
275 if (!bindings[bucket]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
276 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
277 }
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
278 int idx = keycode & 0x7FFF;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
279 keybinding * binding = bindings[bucket] + idx;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
280 handle_binding_down(binding);
1026
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
281 store_key_event(scancode);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
282 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
283
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
284 void handle_joydown(int joystick, int button)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
285 {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
286 if (joystick >= MAX_JOYSTICKS || button >= joysticks[joystick].num_buttons) {
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
287 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
288 }
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
289 keybinding * binding = joysticks[joystick].buttons + button;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
290 handle_binding_down(binding);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
291 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
292
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
293 void handle_mousedown(int mouse, int button)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
294 {
971
e28f365605da Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
295 if (genesis->mouse_mode == MOUSE_CAPTURE && !genesis->mouse_captured) {
e28f365605da Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
296 genesis->mouse_captured = 1;
916
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
297 render_relative_mouse(1);
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
298 return;
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
299 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
300 if (mouse >= MAX_MICE || button > MAX_MOUSE_BUTTONS || button <= 0) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
301 return;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
302 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
303 keybinding * binding = mice[mouse].buttons + button - 1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
304 handle_binding_down(binding);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
305 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
306
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
307 uint8_t ui_debug_mode = 0;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
308 uint8_t ui_debug_pal = 0;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
309
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
310 int current_speed = 0;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
311 int num_speeds = 1;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
312 uint32_t * speeds = NULL;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
313
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
314 void handle_binding_up(keybinding * binding)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
315 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
316 switch(binding->bind_type)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
317 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
318 case BIND_GAMEPAD1:
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
319 case BIND_GAMEPAD2:
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
320 case BIND_GAMEPAD3:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
321 case BIND_GAMEPAD4:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
322 case BIND_GAMEPAD5:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
323 case BIND_GAMEPAD6:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
324 case BIND_GAMEPAD7:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
325 case BIND_GAMEPAD8:
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
326 if (binding->subtype_a <= GAMEPAD_EXTRA && binding->port) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
327 binding->port->input[binding->subtype_a] &= ~binding->value;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
328 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
329 if (binding->subtype_b <= GAMEPAD_EXTRA && binding->port) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
330 binding->port->input[binding->subtype_b] &= ~binding->value;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
331 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
332 break;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
333 case BIND_MOUSE1:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
334 case BIND_MOUSE2:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
335 case BIND_MOUSE3:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
336 case BIND_MOUSE4:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
337 case BIND_MOUSE5:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
338 case BIND_MOUSE6:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
339 case BIND_MOUSE7:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
340 case BIND_MOUSE8:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
341 if (binding->port) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
342 binding->port->input[0] &= ~binding->value;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
343 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
344 break;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
345 case BIND_UI:
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
346 switch (binding->subtype_a)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
347 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
348 case UI_DEBUG_MODE_INC:
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
349 ui_debug_mode++;
771
0565b2c1a034 Add ability to change start address for VRAM viewer. Fix handling of DMA enable flag when it comes to DMA fills. This fixes a bug in James Pond 3
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
350 if (ui_debug_mode == 7) {
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
351 ui_debug_mode = 0;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
352 }
437
afbea09d7fb4 Restore one of the VDP debugging modes
Mike Pavone <pavone@retrodev.com>
parents: 432
diff changeset
353 genesis->vdp->debug = ui_debug_mode;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
354 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
355 case UI_DEBUG_PAL_INC:
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
356 ui_debug_pal++;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
357 if (ui_debug_pal == 4) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
358 ui_debug_pal = 0;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
359 }
722
8f5339961903 Restore the other 2 debug display modes
Michael Pavone <pavone@retrodev.com>
parents: 694
diff changeset
360 genesis->vdp->debug_pal = ui_debug_pal;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
361 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
362 case UI_ENTER_DEBUGGER:
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
363 break_on_sync = 1;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
364 break;
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
365 case UI_SAVE_STATE:
961
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 937
diff changeset
366 genesis->save_state = QUICK_SAVE_SLOT+1;
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
367 break;
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
368 case UI_NEXT_SPEED:
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
369 current_speed++;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
370 if (current_speed >= num_speeds) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
371 current_speed = 0;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
372 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
373 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
374 set_speed_percent(genesis, speeds[current_speed]);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
375 break;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
376 case UI_PREV_SPEED:
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
377 current_speed--;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
378 if (current_speed < 0) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
379 current_speed = num_speeds - 1;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
380 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
381 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
382 set_speed_percent(genesis, speeds[current_speed]);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
383 break;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
384 case UI_SET_SPEED:
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
385 if (binding->value < num_speeds) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
386 current_speed = binding->value;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
387 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
388 set_speed_percent(genesis, speeds[current_speed]);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
389 } else {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
390 printf("Setting speed to %d\n", speeds[current_speed]);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
391 set_speed_percent(genesis, binding->value);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
392 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
393 break;
916
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
394 case UI_RELEASE_MOUSE:
971
e28f365605da Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
395 if (genesis->mouse_captured) {
e28f365605da Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
396 genesis->mouse_captured = 0;
916
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
397 render_relative_mouse(0);
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
398 }
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
399 break;
444
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
400 case UI_EXIT:
883
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 796
diff changeset
401 genesis->m68k->should_return = 1;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
402 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
403 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
404 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
405 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
406
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
407 void handle_keyup(int keycode, uint8_t scancode)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
408 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
409 int bucket = keycode >> 15 & 0xFFFF;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
410 if (!bindings[bucket]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
411 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
412 }
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
413 int idx = keycode & 0x7FFF;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
414 keybinding * binding = bindings[bucket] + idx;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
415 handle_binding_up(binding);
1026
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
416 store_key_event(0x100 | scancode);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
417 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
418
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
419 void handle_joyup(int joystick, int button)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
420 {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
421 if (joystick >= MAX_JOYSTICKS || button >= joysticks[joystick].num_buttons) {
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
422 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
423 }
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
424 keybinding * binding = joysticks[joystick].buttons + button;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
425 handle_binding_up(binding);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
426 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
427
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
428 void handle_joy_dpad(int joystick, int dpadnum, uint8_t value)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
429 {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
430 if (joystick >= MAX_JOYSTICKS || dpadnum >= joysticks[joystick].num_dpads) {
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
431 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
432 }
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
433 joydpad * dpad = joysticks[joystick].dpads + dpadnum;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
434 uint8_t newdown = (value ^ dpad->state) & value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
435 uint8_t newup = ((~value) ^ (~dpad->state)) & (~value);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
436 dpad->state = value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
437 for (int i = 0; i < 4; i++) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
438 if (newdown & dpadbits[i]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
439 handle_binding_down(dpad->bindings + i);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
440 } else if(newup & dpadbits[i]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
441 handle_binding_up(dpad->bindings + i);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
442 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
443 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
444 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
445
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
446 void handle_mouseup(int mouse, int button)
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
447 {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
448 if (mouse >= MAX_MICE || button > MAX_MOUSE_BUTTONS || button <= 0) {
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
449 return;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
450 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
451 keybinding * binding = mice[mouse].buttons + button - 1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
452 handle_binding_up(binding);
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
453 }
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
454
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
455 void handle_mouse_moved(int mouse, uint16_t x, uint16_t y, int16_t deltax, int16_t deltay)
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
456 {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
457 if (mouse >= MAX_MICE || !mice[mouse].motion_port) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
458 return;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
459 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
460 //TODO: relative mode
971
e28f365605da Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
461 switch(genesis->mouse_mode)
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
462 {
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
463 case MOUSE_ABSOLUTE: {
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
464 float scale_x = 640.0 / ((float)render_width());
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
465 float scale_y = 480.0 / ((float)render_height());
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
466 float scale = scale_x > scale_y ? scale_y : scale_x;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
467 mice[mouse].motion_port->device.mouse.cur_x = x * scale_x;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
468 mice[mouse].motion_port->device.mouse.cur_y = y * scale_y;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
469 break;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
470 }
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
471 case MOUSE_RELATIVE: {
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
472 mice[mouse].motion_port->device.mouse.cur_x += deltax;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
473 mice[mouse].motion_port->device.mouse.cur_y += deltay;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
474 break;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
475 }
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
476 case MOUSE_CAPTURE: {
971
e28f365605da Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
477 if (genesis->mouse_captured) {
916
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
478 mice[mouse].motion_port->device.mouse.cur_x += deltax;
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
479 mice[mouse].motion_port->device.mouse.cur_y += deltay;
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
480 }
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
481 }
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
482 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
483 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
484
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
485 int parse_binding_target(char * target, tern_node * padbuttons, tern_node *mousebuttons, int * ui_out, int * padnum_out, int * padbutton_out)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
486 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
487 const int gpadslen = strlen("gamepads.");
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
488 const int mouselen = strlen("mouse.");
796
41f73c76b978 Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 771
diff changeset
489 if (!strncmp(target, "gamepads.", gpadslen)) {
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
490 if (target[gpadslen] >= '1' && target[gpadslen] <= '8') {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
491 int padnum = target[gpadslen] - '0';
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
492 int button = tern_find_int(padbuttons, target + gpadslen + 1, 0);
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
493 if (button) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
494 *padnum_out = padnum;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
495 *padbutton_out = button;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
496 return BIND_GAMEPAD1;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
497 } else {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
498 if (target[gpadslen+1]) {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
499 warning("Gamepad mapping string '%s' refers to an invalid button '%s'\n", target, target + gpadslen + 1);
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
500 } else {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
501 warning("Gamepad mapping string '%s' has no button component\n", target);
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
502 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
503 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
504 } else {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
505 warning("Gamepad mapping string '%s' refers to an invalid gamepad number %c\n", target, target[gpadslen]);
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
506 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
507 } else if(!strncmp(target, "mouse.", mouselen)) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
508 if (target[mouselen] >= '1' && target[mouselen] <= '8') {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
509 int mousenum = target[mouselen] - '0';
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
510 int button = tern_find_int(mousebuttons, target + mouselen + 1, 0);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
511 if (button) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
512 *padnum_out = mousenum;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
513 *padbutton_out = button;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
514 return BIND_MOUSE1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
515 } else {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
516 if (target[mouselen+1]) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
517 warning("Mouse mapping string '%s' refers to an invalid button '%s'\n", target, target + mouselen + 1);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
518 } else {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
519 warning("Mouse mapping string '%s' has no button component\n", target);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
520 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
521 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
522 } else {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
523 warning("Gamepad mapping string '%s' refers to an invalid mouse number %c\n", target, target[mouselen]);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
524 }
796
41f73c76b978 Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 771
diff changeset
525 } else if(!strncmp(target, "ui.", strlen("ui."))) {
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
526 *padbutton_out = 0;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
527 if (!strcmp(target + 3, "vdp_debug_mode")) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
528 *ui_out = UI_DEBUG_MODE_INC;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
529 } else if(!strcmp(target + 3, "vdp_debug_pal")) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
530 *ui_out = UI_DEBUG_PAL_INC;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
531 } else if(!strcmp(target + 3, "enter_debugger")) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
532 *ui_out = UI_ENTER_DEBUGGER;
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
533 } else if(!strcmp(target + 3, "save_state")) {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
534 *ui_out = UI_SAVE_STATE;
796
41f73c76b978 Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 771
diff changeset
535 } else if(!strncmp(target + 3, "set_speed.", strlen("set_speed."))) {
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
536 *ui_out = UI_SET_SPEED;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
537 *padbutton_out = atoi(target + 3 + strlen("set_speed."));
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
538 } else if(!strcmp(target + 3, "next_speed")) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
539 *ui_out = UI_NEXT_SPEED;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
540 } else if(!strcmp(target + 3, "prev_speed")) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
541 *ui_out = UI_PREV_SPEED;
916
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
542 } else if(!strcmp(target + 3, "release_mouse")) {
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
543 *ui_out = UI_RELEASE_MOUSE;
444
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
544 } else if(!strcmp(target + 3, "exit")) {
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
545 *ui_out = UI_EXIT;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
546 } else {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
547 warning("Unreconized UI binding type %s\n", target);
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
548 return 0;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
549 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
550 return BIND_UI;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
551 } else {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
552 warning("Unrecognized binding type %s\n", target);
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
553 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
554 return 0;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
555 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
556
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
557 void process_keys(tern_node * cur, tern_node * special, tern_node * padbuttons, tern_node *mousebuttons, char * prefix)
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
558 {
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
559 char * curstr = NULL;
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
560 int len;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
561 if (!cur) {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
562 return;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
563 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
564 char onec[2];
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
565 if (prefix) {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
566 len = strlen(prefix);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
567 curstr = malloc(len + 2);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
568 memcpy(curstr, prefix, len);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
569 } else {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
570 curstr = onec;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
571 len = 0;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
572 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
573 curstr[len] = cur->el;
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
574 curstr[len+1] = 0;
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
575 if (cur->el) {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
576 process_keys(cur->straight.next, special, padbuttons, mousebuttons, curstr);
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
577 } else {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
578 int keycode = tern_find_int(special, curstr, 0);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
579 if (!keycode) {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
580 keycode = curstr[0];
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
581 if (curstr[1] != 0) {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
582 warning("%s is not recognized as a key identifier, truncating to %c\n", curstr, curstr[0]);
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
583 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
584 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
585 char * target = cur->straight.value.ptrval;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
586 int ui_func, padnum, button;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
587 int bindtype = parse_binding_target(target, padbuttons, mousebuttons, &ui_func, &padnum, &button);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
588 if (bindtype == BIND_GAMEPAD1) {
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
589 bind_gamepad(keycode, padnum, button);
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
590 } else if(bindtype == BIND_UI) {
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
591 bind_ui(keycode, ui_func, button);
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
592 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
593 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
594 process_keys(cur->left, special, padbuttons, mousebuttons, prefix);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
595 process_keys(cur->right, special, padbuttons, mousebuttons, prefix);
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
596 if (curstr && len) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
597 free(curstr);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
598 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
599 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
600
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
601 void process_speeds(tern_node * cur, char * prefix)
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
602 {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
603 char * curstr = NULL;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
604 int len;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
605 if (!cur) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
606 return;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
607 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
608 char onec[2];
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
609 if (prefix) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
610 len = strlen(prefix);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
611 curstr = malloc(len + 2);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
612 memcpy(curstr, prefix, len);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
613 } else {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
614 curstr = onec;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
615 len = 0;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
616 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
617 curstr[len] = cur->el;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
618 curstr[len+1] = 0;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
619 if (cur->el) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
620 process_speeds(cur->straight.next, curstr);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
621 } else {
1005
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
622 char *end;
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
623 long speed_index = strtol(curstr, &end, 10);
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
624 if (speed_index < 0 || end == curstr || *end) {
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
625 warning("%s is not a valid speed index", curstr);
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
626 } else {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
627 if (speed_index >= num_speeds) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
628 speeds = realloc(speeds, sizeof(uint32_t) * (speed_index+1));
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
629 for(; num_speeds < speed_index + 1; num_speeds++) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
630 speeds[num_speeds] = 0;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
631 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
632 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
633 speeds[speed_index] = atoi(cur->straight.value.ptrval);
1005
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
634 if (speeds[speed_index] < 1) {
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
635 warning("%s is not a valid speed percentage, setting speed %d to 100", cur->straight.value.ptrval, speed_index);
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
636 speeds[speed_index] = 100;
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
637 }
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
638 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
639 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
640 process_speeds(cur->left, prefix);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
641 process_speeds(cur->right, prefix);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
642 if (curstr && len) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
643 free(curstr);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
644 }
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
645 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
646
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
647 void process_device(char * device_type, io_port * port)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
648 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
649 port->device_type = IO_NONE;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
650 if (!device_type)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
651 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
652 return;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
653 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
654
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
655 const int gamepad_len = strlen("gamepad");
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
656 const int mouse_len = strlen("mouse");
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
657 if (!strncmp(device_type, "gamepad", gamepad_len))
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
658 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
659 if (
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
660 (device_type[gamepad_len] != '3' && device_type[gamepad_len] != '6')
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
661 || device_type[gamepad_len+1] != '.' || device_type[gamepad_len+2] < '1'
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
662 || device_type[gamepad_len+2] > '8' || device_type[gamepad_len+3] != 0
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
663 )
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
664 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
665 warning("%s is not a valid gamepad type\n", device_type);
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
666 } else if (device_type[gamepad_len] == '3')
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
667 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
668 port->device_type = IO_GAMEPAD3;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
669 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
670 port->device_type = IO_GAMEPAD6;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
671 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
672 port->device.pad.gamepad_num = device_type[gamepad_len+2] - '1';
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
673 } else if(!strncmp(device_type, "mouse", mouse_len)) {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
674 port->device_type = IO_MOUSE;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
675 port->device.mouse.mouse_num = device_type[mouse_len+1] - '1';
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
676 port->device.mouse.last_read_x = 0;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
677 port->device.mouse.last_read_y = 0;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
678 port->device.mouse.cur_x = 0;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
679 port->device.mouse.cur_y = 0;
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
680 port->device.mouse.latched_x = 0;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
681 port->device.mouse.latched_y = 0;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
682 port->device.mouse.ready_cycle = CYCLE_NEVER;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
683 port->device.mouse.tr_counter = 0;
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
684 } else if(!strcmp(device_type, "saturn keyboard")) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
685 port->device_type = IO_SATURN_KEYBOARD;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
686 port->device.keyboard.read_pos = 0xFF;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
687 port->device.keyboard.write_pos = 0;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
688 } else if(!strcmp(device_type, "sega_parallel")) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
689 port->device_type = IO_SEGA_PARALLEL;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
690 port->device.stream.data_fd = -1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
691 port->device.stream.listen_fd = -1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
692 } else if(!strcmp(device_type, "generic")) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
693 port->device_type = IO_GENERIC;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
694 port->device.stream.data_fd = -1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
695 port->device.stream.listen_fd = -1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
696 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
697 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
698
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
699 char * io_name(int i)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
700 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
701 switch (i)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
702 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
703 case 0:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
704 return "1";
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
705 case 1:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
706 return "2";
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
707 case 2:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
708 return "EXT";
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
709 default:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
710 return "invalid";
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
711 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
712 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
713
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
714 static char * sockfile_name;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
715 static void cleanup_sockfile()
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
716 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
717 unlink(sockfile_name);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
718 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
719
971
e28f365605da Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
720 void setup_io_devices(tern_node * config, rom_info *rom, genesis_context *gen)
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
721 {
971
e28f365605da Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
722 io_port * ports = gen->ports;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
723 tern_node *io_nodes = tern_get_node(tern_find_path(config, "io\0devices\0"));
913
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 912
diff changeset
724 char * io_1 = rom->port1_override ? rom->port1_override : tern_find_ptr(io_nodes, "1");
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 912
diff changeset
725 char * io_2 = rom->port2_override ? rom->port2_override : tern_find_ptr(io_nodes, "2");
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 912
diff changeset
726 char * io_ext = rom->ext_override ? rom->ext_override : tern_find_ptr(io_nodes, "ext");
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
727
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
728 process_device(io_1, ports);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
729 process_device(io_2, ports+1);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
730 process_device(io_ext, ports+2);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
731
916
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
732 if (render_fullscreen()) {
971
e28f365605da Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
733 gen->mouse_mode = MOUSE_RELATIVE;
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
734 render_relative_mouse(1);
916
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
735 } else {
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
736 if (rom->mouse_mode && !strcmp(rom->mouse_mode, "absolute")) {
971
e28f365605da Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
737 gen->mouse_mode = MOUSE_ABSOLUTE;
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
738 } else {
971
e28f365605da Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
739 gen->mouse_mode = MOUSE_CAPTURE;
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
740 }
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
741 }
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
742
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
743 for (int i = 0; i < 3; i++)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
744 {
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
745 #ifndef _WIN32
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
746 if (ports[i].device_type == IO_SEGA_PARALLEL)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
747 {
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
748 char *pipe_name = tern_find_path(config, "io\0parallel_pipe\0").ptrval;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
749 if (!pipe_name)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
750 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
751 warning("IO port %s is configured to use the sega parallel board, but no paralell_pipe is set!\n", io_name(i));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
752 ports[i].device_type = IO_NONE;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
753 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
754 printf("IO port: %s connected to device '%s' with pipe name: %s\n", io_name(i), device_type_names[ports[i].device_type], pipe_name);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
755 if (!strcmp("stdin", pipe_name))
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
756 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
757 ports[i].device.stream.data_fd = STDIN_FILENO;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
758 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
759 if (mkfifo(pipe_name, 0666) && errno != EEXIST)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
760 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
761 warning("Failed to create fifo %s for Sega parallel board emulation: %d %s\n", pipe_name, errno, strerror(errno));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
762 ports[i].device_type = IO_NONE;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
763 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
764 ports[i].device.stream.data_fd = open(pipe_name, O_NONBLOCK | O_RDONLY);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
765 if (ports[i].device.stream.data_fd == -1)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
766 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
767 warning("Failed to open fifo %s for Sega parallel board emulation: %d %s\n", pipe_name, errno, strerror(errno));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
768 ports[i].device_type = IO_NONE;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
769 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
770 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
771 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
772 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
773 } else if (ports[i].device_type == IO_GENERIC) {
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
774 char *sock_name = tern_find_path(config, "io\0socket\0").ptrval;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
775 if (!sock_name)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
776 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
777 warning("IO port %s is configured to use generic IO, but no socket is set!\n", io_name(i));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
778 ports[i].device_type = IO_NONE;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
779 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
780 printf("IO port: %s connected to device '%s' with socket name: %s\n", io_name(i), device_type_names[ports[i].device_type], sock_name);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
781 ports[i].device.stream.data_fd = -1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
782 ports[i].device.stream.listen_fd = socket(AF_UNIX, SOCK_STREAM, 0);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
783 size_t pathlen = strlen(sock_name);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
784 size_t addrlen = offsetof(struct sockaddr_un, sun_path) + pathlen + 1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
785 struct sockaddr_un *saddr = malloc(addrlen);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
786 saddr->sun_family = AF_UNIX;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
787 memcpy(saddr->sun_path, sock_name, pathlen+1);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
788 if (bind(ports[i].device.stream.listen_fd, (struct sockaddr *)saddr, addrlen))
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
789 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
790 warning("Failed to bind socket for IO Port %s to path %s: %d %s\n", io_name(i), sock_name, errno, strerror(errno));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
791 goto cleanup_sock;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
792 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
793 if (listen(ports[i].device.stream.listen_fd, 1))
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
794 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
795 warning("Failed to listen on socket for IO Port %s: %d %s\n", io_name(i), errno, strerror(errno));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
796 goto cleanup_sockfile;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
797 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
798 sockfile_name = sock_name;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
799 atexit(cleanup_sockfile);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
800 continue;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
801 cleanup_sockfile:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
802 unlink(sock_name);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
803 cleanup_sock:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
804 close(ports[i].device.stream.listen_fd);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
805 ports[i].device_type = IO_NONE;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
806 }
883
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 796
diff changeset
807 } else
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
808 #endif
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
809 if (ports[i].device_type == IO_GAMEPAD3 || ports[i].device_type == IO_GAMEPAD6) {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
810 printf("IO port %s connected to gamepad #%d with type '%s'\n", io_name(i), ports[i].device.pad.gamepad_num + 1, device_type_names[ports[i].device_type]);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
811 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
812 printf("IO port %s connected to device '%s'\n", io_name(i), device_type_names[ports[i].device_type]);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
813 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
814 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
815 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
816
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
817 void map_bindings(io_port *ports, keybinding *bindings, int numbindings)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
818 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
819 for (int i = 0; i < numbindings; i++)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
820 {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
821 if (bindings[i].bind_type >= BIND_GAMEPAD1 && bindings[i].bind_type <= BIND_GAMEPAD8)
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
822 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
823 int num = bindings[i].bind_type - BIND_GAMEPAD1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
824 for (int j = 0; j < 3; j++)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
825 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
826 if ((ports[j].device_type == IO_GAMEPAD3
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
827 || ports[j].device_type ==IO_GAMEPAD6)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
828 && ports[j].device.pad.gamepad_num == num
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
829 )
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
830 {
886
fb1f11fd0692 Clear out IO port input state when setting bindings. This fixes a bug where pressing start in the menu after returning to it only worked on the second try.
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
831 memset(ports[j].input, 0, sizeof(ports[j].input));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
832 bindings[i].port = ports + j;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
833 break;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
834 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
835 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
836 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
837 else if (bindings[i].bind_type >= BIND_MOUSE1 && bindings[i].bind_type <= BIND_MOUSE8)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
838 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
839 int num = bindings[i].bind_type - BIND_MOUSE1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
840 for (int j = 0; j < 3; j++)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
841 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
842 if (ports[j].device_type == IO_MOUSE && ports[j].device.mouse.mouse_num == num)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
843 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
844 memset(ports[j].input, 0, sizeof(ports[j].input));
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
845 bindings[i].port = ports + j;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
846 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
847 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
848 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
849 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
850 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
851 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
852
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
853 typedef struct {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
854 tern_node *padbuttons;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
855 tern_node *mousebuttons;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
856 int mouseidx;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
857 } pmb_state;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
858
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
859 void process_mouse_button(char *buttonstr, tern_val value, void *data)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
860 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
861 pmb_state *state = data;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
862 int buttonnum = atoi(buttonstr);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
863 if (buttonnum < 1 || buttonnum > MAX_MOUSE_BUTTONS) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
864 warning("Mouse button %s is out of the supported range of 1-8\n", buttonstr);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
865 return;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
866 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
867 buttonnum--;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
868 int ui_func, devicenum, button;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
869 int bindtype = parse_binding_target(value.ptrval, state->padbuttons, state->mousebuttons, &ui_func, &devicenum, &button);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
870 switch (bindtype)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
871 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
872 case BIND_UI:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
873 mice[state->mouseidx].buttons[buttonnum].subtype_a = ui_func;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
874 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
875 case BIND_GAMEPAD1:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
876 mice[state->mouseidx].buttons[buttonnum].subtype_a = button >> 12;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
877 mice[state->mouseidx].buttons[buttonnum].subtype_b = button >> 8 & 0xF;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
878 mice[state->mouseidx].buttons[buttonnum].value = button & 0xFF;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
879 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
880 case BIND_MOUSE1:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
881 mice[state->mouseidx].buttons[buttonnum].value = button & 0xFF;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
882 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
883 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
884 if (bindtype != BIND_UI) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
885 bindtype += devicenum-1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
886 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
887 mice[state->mouseidx].buttons[buttonnum].bind_type = bindtype;
913
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 912
diff changeset
888
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
889 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
890
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
891 void process_mouse(char *mousenum, tern_val value, void *data)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
892 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
893 tern_node **buttonmaps = data;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
894 tern_node *mousedef = tern_get_node(value);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
895 tern_node *padbuttons = buttonmaps[0];
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
896 tern_node *mousebuttons = buttonmaps[1];
913
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 912
diff changeset
897
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
898 if (!mousedef) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
899 warning("Binding for mouse %s is a scalar!\n", mousenum);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
900 return;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
901 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
902 int mouseidx = atoi(mousenum);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
903 if (mouseidx < 0 || mouseidx >= MAX_MICE) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
904 warning("Mouse numbers must be between 0 and %d, but %d is not\n", MAX_MICE, mouseidx);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
905 return;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
906 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
907 char *motion = tern_find_ptr(mousedef, "motion");
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
908 if (motion) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
909 int ui_func,devicenum,button;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
910 int bindtype = parse_binding_target(motion, padbuttons, mousebuttons, &ui_func, &devicenum, &button);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
911 if (bindtype != BIND_UI) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
912 bindtype += devicenum-1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
913 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
914 if (button == PSEUDO_BUTTON_MOTION) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
915 mice[mouseidx].bind_type = bindtype;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
916 } else {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
917 warning("Mouse motion can't be bound to target %s\n", motion);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
918 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
919 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
920 tern_node *buttons = tern_get_node(tern_find_path(mousedef, "buttons\0\0"));
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
921 if (buttons) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
922 pmb_state state = {padbuttons, mousebuttons, mouseidx};
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
923 tern_foreach(buttons, process_mouse_button, &state);
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
924 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
925 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
926
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
927 void set_keybindings(io_port *ports)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
928 {
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
929 tern_node * special = tern_insert_int(NULL, "up", RENDERKEY_UP);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
930 special = tern_insert_int(special, "down", RENDERKEY_DOWN);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
931 special = tern_insert_int(special, "left", RENDERKEY_LEFT);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
932 special = tern_insert_int(special, "right", RENDERKEY_RIGHT);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
933 special = tern_insert_int(special, "enter", '\r');
1035
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
934 special = tern_insert_int(special, "space", ' ');
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
935 special = tern_insert_int(special, "tab", '\t');
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
936 special = tern_insert_int(special, "backspace", '\b');
504
7b0df1aaf384 Add support for left and right shift keys
Mike Pavone <pavone@retrodev.com>
parents: 493
diff changeset
937 special = tern_insert_int(special, "esc", RENDERKEY_ESC);
1035
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
938 special = tern_insert_int(special, "delete", RENDERKEY_DEL);
504
7b0df1aaf384 Add support for left and right shift keys
Mike Pavone <pavone@retrodev.com>
parents: 493
diff changeset
939 special = tern_insert_int(special, "lshift", RENDERKEY_LSHIFT);
7b0df1aaf384 Add support for left and right shift keys
Mike Pavone <pavone@retrodev.com>
parents: 493
diff changeset
940 special = tern_insert_int(special, "rshift", RENDERKEY_RSHIFT);
1035
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
941 special = tern_insert_int(special, "lctrl", RENDERKEY_LCTRL);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
942 special = tern_insert_int(special, "rctrl", RENDERKEY_RCTRL);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
943 special = tern_insert_int(special, "lalt", RENDERKEY_LALT);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
944 special = tern_insert_int(special, "ralt", RENDERKEY_RALT);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
945 special = tern_insert_int(special, "home", RENDERKEY_HOME);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
946 special = tern_insert_int(special, "end", RENDERKEY_END);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
947 special = tern_insert_int(special, "pageup", RENDERKEY_PAGEUP);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
948 special = tern_insert_int(special, "pagedown", RENDERKEY_PAGEDOWN);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
949 special = tern_insert_int(special, "f1", RENDERKEY_F1);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
950 special = tern_insert_int(special, "f2", RENDERKEY_F2);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
951 special = tern_insert_int(special, "f3", RENDERKEY_F3);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
952 special = tern_insert_int(special, "f4", RENDERKEY_F4);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
953 special = tern_insert_int(special, "f5", RENDERKEY_F5);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
954 special = tern_insert_int(special, "f6", RENDERKEY_F6);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
955 special = tern_insert_int(special, "f7", RENDERKEY_F7);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
956 special = tern_insert_int(special, "f8", RENDERKEY_F8);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
957 special = tern_insert_int(special, "f9", RENDERKEY_F9);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
958 special = tern_insert_int(special, "f10", RENDERKEY_F10);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
959 special = tern_insert_int(special, "f11", RENDERKEY_F11);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
960 special = tern_insert_int(special, "f12", RENDERKEY_F12);
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
961 special = tern_insert_int(special, "select", RENDERKEY_SELECT);
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
962 special = tern_insert_int(special, "play", RENDERKEY_PLAY);
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
963 special = tern_insert_int(special, "search", RENDERKEY_SEARCH);
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
964 special = tern_insert_int(special, "back", RENDERKEY_BACK);
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
965
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
966 tern_node * padbuttons = tern_insert_int(NULL, ".up", DPAD_UP);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
967 padbuttons = tern_insert_int(padbuttons, ".down", DPAD_DOWN);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
968 padbuttons = tern_insert_int(padbuttons, ".left", DPAD_LEFT);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
969 padbuttons = tern_insert_int(padbuttons, ".right", DPAD_RIGHT);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
970 padbuttons = tern_insert_int(padbuttons, ".a", BUTTON_A);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
971 padbuttons = tern_insert_int(padbuttons, ".b", BUTTON_B);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
972 padbuttons = tern_insert_int(padbuttons, ".c", BUTTON_C);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
973 padbuttons = tern_insert_int(padbuttons, ".x", BUTTON_X);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
974 padbuttons = tern_insert_int(padbuttons, ".y", BUTTON_Y);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
975 padbuttons = tern_insert_int(padbuttons, ".z", BUTTON_Z);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
976 padbuttons = tern_insert_int(padbuttons, ".start", BUTTON_START);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
977 padbuttons = tern_insert_int(padbuttons, ".mode", BUTTON_MODE);
913
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 912
diff changeset
978
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
979 tern_node *mousebuttons = tern_insert_int(NULL, ".left", MOUSE_LEFT);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
980 mousebuttons = tern_insert_int(mousebuttons, ".middle", MOUSE_MIDDLE);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
981 mousebuttons = tern_insert_int(mousebuttons, ".right", MOUSE_RIGHT);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
982 mousebuttons = tern_insert_int(mousebuttons, ".start", MOUSE_START);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
983 mousebuttons = tern_insert_int(mousebuttons, ".motion", PSEUDO_BUTTON_MOTION);
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
984
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
985 tern_node * keys = tern_get_node(tern_find_path(config, "bindings\0keys\0"));
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
986 process_keys(keys, special, padbuttons, mousebuttons, NULL);
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
987 char numstr[] = "00";
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
988 tern_node * pads = tern_get_node(tern_find_path(config, "bindings\0pads\0"));
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
989 if (pads) {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
990 for (int i = 0; i < MAX_JOYSTICKS; i++)
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
991 {
883
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 796
diff changeset
992
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
993 if (i < 10) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
994 numstr[0] = i + '0';
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
995 numstr[1] = 0;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
996 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
997 numstr[0] = i/10 + '0';
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
998 numstr[1] = i%10 + '0';
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
999 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1000 tern_node * pad = tern_find_ptr(pads, numstr);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1001 if (pad) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1002 tern_node * dpad_node = tern_find_ptr(pad, "dpads");
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1003 if (dpad_node) {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1004 for (int dpad = 0; dpad < 10; dpad++)
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1005 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1006 numstr[0] = dpad + '0';
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1007 numstr[1] = 0;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1008 tern_node * pad_dpad = tern_find_ptr(dpad_node, numstr);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1009 char * dirs[] = {"up", "down", "left", "right"};
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1010 int dirnums[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT};
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1011 for (int dir = 0; dir < sizeof(dirs)/sizeof(dirs[0]); dir++) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1012 char * target = tern_find_ptr(pad_dpad, dirs[dir]);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1013 if (target) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1014 int ui_func, padnum, button;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1015 int bindtype = parse_binding_target(target, padbuttons, mousebuttons, &ui_func, &padnum, &button);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1016 if (bindtype == BIND_GAMEPAD1) {
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1017 bind_dpad_gamepad(i, dpad, dirnums[dir], padnum, button);
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1018 } else if (bindtype == BIND_UI) {
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1019 bind_dpad_ui(i, dpad, dirnums[dir], ui_func, button);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1020 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1021 }
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
1022 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
1023 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
1024 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1025 tern_node *button_node = tern_find_ptr(pad, "buttons");
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1026 if (button_node) {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1027 for (int but = 0; but < 30; but++)
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1028 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1029 if (but < 10) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1030 numstr[0] = but + '0';
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1031 numstr[1] = 0;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1032 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1033 numstr[0] = but/10 + '0';
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1034 numstr[1] = but%10 + '0';
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1035 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1036 char * target = tern_find_ptr(button_node, numstr);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1037 if (target) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1038 int ui_func, padnum, button;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1039 int bindtype = parse_binding_target(target, padbuttons, mousebuttons, &ui_func, &padnum, &button);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1040 if (bindtype == BIND_GAMEPAD1) {
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1041 bind_button_gamepad(i, but, padnum, button);
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1042 } else if (bindtype == BIND_UI) {
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1043 bind_button_ui(i, but, ui_func, button);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1044 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1045 }
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
1046 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
1047 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
1048 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
1049 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
1050 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1051 memset(mice, 0, sizeof(mice));
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1052 tern_node * mice = tern_get_node(tern_find_path(config, "bindings\0mice\0"));
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1053 if (mice) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1054 tern_node *buttonmaps[2] = {padbuttons, mousebuttons};
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1055 tern_foreach(mice, process_mouse, buttonmaps);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1056 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1057 tern_node * speed_nodes = tern_get_node(tern_find_path(config, "clocks\0speeds\0"));
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
1058 speeds = malloc(sizeof(uint32_t));
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
1059 speeds[0] = 100;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
1060 process_speeds(speed_nodes, NULL);
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1061 for (int i = 0; i < num_speeds; i++)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1062 {
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
1063 if (!speeds[i]) {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1064 warning("Speed index %d was not set to a valid percentage!", i);
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
1065 speeds[i] = 100;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
1066 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
1067 }
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1068 map_all_bindings(ports);
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1069 }
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1070
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1071 void map_all_bindings(io_port *ports)
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1072 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1073 for (int bucket = 0; bucket < 0x10000; bucket++)
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1074 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1075 if (bindings[bucket])
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1076 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1077 map_bindings(ports, bindings[bucket], 0x8000);
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1078 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1079 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1080 for (int stick = 0; stick < MAX_JOYSTICKS; stick++)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1081 {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1082 if (joysticks[stick].buttons) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1083 map_bindings(ports, joysticks[stick].buttons, joysticks[stick].num_buttons);
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1084 }
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1085 if (joysticks[stick].dpads)
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1086 {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1087 for (uint32_t i = 0; i < joysticks[stick].num_dpads; i++) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1088 map_bindings(ports, joysticks[stick].dpads[i].bindings, 4);
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1089 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1090 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1091 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1092 for (int mouse = 0; mouse < MAX_MICE; mouse++)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1093 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1094 if (mice[mouse].bind_type >= BIND_MOUSE1 && mice[mouse].bind_type <= BIND_MOUSE8) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1095 int num = mice[mouse].bind_type - BIND_MOUSE1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1096 for (int j = 0; j < 3; j++)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1097 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1098 if (ports[j].device_type == IO_MOUSE && ports[j].device.mouse.mouse_num == num)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1099 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1100 memset(ports[j].input, 0, sizeof(ports[j].input));
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1101 mice[mouse].motion_port = ports + j;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1102 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1103 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1104 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1105 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1106 map_bindings(ports, mice[mouse].buttons, MAX_MOUSE_BUTTONS);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1107 }
1026
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
1108 keyboard_port = NULL;
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
1109 for (int i = 0; i < 3; i++)
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
1110 {
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
1111 if (ports[i].device_type == IO_SATURN_KEYBOARD) {
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
1112 keyboard_port = ports + i;
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
1113 break;
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
1114 }
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
1115 }
1005
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
1116 //not really related to the intention of this function, but the best place to do this currently
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
1117 if (speeds[0] != 100) {
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
1118 set_speed_percent(genesis, speeds[0]);
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
1119 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1120 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1121
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1122 #define TH 0x40
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1123 #define TR 0x20
694
7497334bb548 Adjust TH timeout value to take into account the move to master clock cycles
Michael Pavone <pavone@retrodev.com>
parents: 645
diff changeset
1124 #define TH_TIMEOUT 56000
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1125
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1126 void mouse_check_ready(io_port *port, uint32_t current_cycle)
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1127 {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1128 if (current_cycle >= port->device.mouse.ready_cycle) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1129 port->device.mouse.tr_counter++;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1130 port->device.mouse.ready_cycle = CYCLE_NEVER;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1131 if (port->device.mouse.tr_counter == 3) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1132 port->device.mouse.latched_x = port->device.mouse.cur_x;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1133 port->device.mouse.latched_y = port->device.mouse.cur_y;
971
e28f365605da Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
1134 if (genesis->mouse_mode == MOUSE_ABSOLUTE) {
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1135 //avoid overflow in absolute mode
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1136 int deltax = port->device.mouse.latched_x - port->device.mouse.last_read_x;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1137 if (abs(deltax) > 255) {
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1138 port->device.mouse.latched_x = port->device.mouse.last_read_x + (deltax > 0 ? 255 : -255);
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1139 }
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1140 int deltay = port->device.mouse.latched_y - port->device.mouse.last_read_y;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1141 if (abs(deltay) > 255) {
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1142 port->device.mouse.latched_y = port->device.mouse.last_read_y + (deltay > 0 ? 255 : -255);
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1143 }
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1144 }
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1145 }
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1146 }
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1147 }
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1148
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1149 void io_adjust_cycles(io_port * port, uint32_t current_cycle, uint32_t deduction)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1150 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1151 /*uint8_t control = pad->control | 0x80;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1152 uint8_t th = control & pad->output;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1153 if (pad->input[GAMEPAD_TH0] || pad->input[GAMEPAD_TH1]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1154 printf("adjust_cycles | control: %X, TH: %X, GAMEPAD_TH0: %X, GAMEPAD_TH1: %X, TH Counter: %d, Timeout: %d, Cycle: %d\n", control, th, pad->input[GAMEPAD_TH0], pad->input[GAMEPAD_TH1], pad->th_counter,pad->timeout_cycle, current_cycle);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1155 }*/
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1156 if (port->device_type == IO_GAMEPAD6)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1157 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1158 if (current_cycle >= port->device.pad.timeout_cycle)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1159 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1160 port->device.pad.th_counter = 0;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1161 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1162 port->device.pad.timeout_cycle -= deduction;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1163 }
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1164 } else if (port->device_type == IO_MOUSE) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1165 mouse_check_ready(port, current_cycle);
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1166 if (port->device.mouse.ready_cycle != CYCLE_NEVER) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1167 port->device.mouse.ready_cycle -= deduction;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1168 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1169 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1170 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1171
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1172 #ifndef _WIN32
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1173 static void wait_for_connection(io_port * port)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1174 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1175 if (port->device.stream.data_fd == -1)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1176 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1177 puts("Waiting for socket connection...");
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1178 port->device.stream.data_fd = accept(port->device.stream.listen_fd, NULL, NULL);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1179 fcntl(port->device.stream.data_fd, F_SETFL, O_NONBLOCK | O_RDWR);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1180 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1181 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1182
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1183 static void service_pipe(io_port * port)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1184 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1185 uint8_t value;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1186 int numRead = read(port->device.stream.data_fd, &value, sizeof(value));
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1187 if (numRead > 0)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1188 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1189 port->input[IO_TH0] = (value & 0xF) | 0x10;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1190 port->input[IO_TH1] = (value >> 4) | 0x10;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1191 } else if(numRead == -1 && errno != EAGAIN && errno != EWOULDBLOCK) {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1192 warning("Error reading pipe for IO port: %d %s\n", errno, strerror(errno));
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1193 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1194 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1195
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1196 static void service_socket(io_port *port)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1197 {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1198 uint8_t buf[32];
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1199 uint8_t blocking = 0;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1200 int numRead = 0;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1201 while (numRead <= 0)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1202 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1203 numRead = recv(port->device.stream.data_fd, buf, sizeof(buf), 0);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1204 if (numRead > 0)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1205 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1206 port->input[IO_TH0] = buf[numRead-1];
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1207 if (port->input[IO_STATE] == IO_READ_PENDING)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1208 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1209 port->input[IO_STATE] = IO_READ;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1210 if (blocking)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1211 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1212 //pending read satisfied, back to non-blocking mode
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1213 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR | O_NONBLOCK);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1214 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1215 } else if (port->input[IO_STATE] == IO_WRITTEN) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1216 port->input[IO_STATE] = IO_READ;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1217 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1218 } else if (numRead == 0) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1219 port->device.stream.data_fd = -1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1220 wait_for_connection(port);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1221 } else if (errno != EAGAIN && errno != EWOULDBLOCK) {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1222 warning("Error reading from socket for IO port: %d %s\n", errno, strerror(errno));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1223 close(port->device.stream.data_fd);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1224 wait_for_connection(port);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1225 } else if (port->input[IO_STATE] == IO_READ_PENDING) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1226 //clear the nonblocking flag so the next read will block
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1227 if (!blocking)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1228 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1229 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1230 blocking = 1;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1231 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1232 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1233 //no new data, but that's ok
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1234 break;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1235 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1236 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1237
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1238 if (port->input[IO_STATE] == IO_WRITE_PENDING)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1239 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1240 uint8_t value = port->output & port->control;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1241 int written = 0;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1242 blocking = 0;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1243 while (written <= 0)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1244 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1245 send(port->device.stream.data_fd, &value, sizeof(value), 0);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1246 if (written > 0)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1247 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1248 port->input[IO_STATE] = IO_WRITTEN;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1249 if (blocking)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1250 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1251 //pending write satisfied, back to non-blocking mode
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1252 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR | O_NONBLOCK);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1253 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1254 } else if (written == 0) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1255 port->device.stream.data_fd = -1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1256 wait_for_connection(port);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1257 } else if (errno != EAGAIN && errno != EWOULDBLOCK) {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1258 warning("Error writing to socket for IO port: %d %s\n", errno, strerror(errno));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1259 close(port->device.stream.data_fd);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1260 wait_for_connection(port);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1261 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1262 //clear the nonblocking flag so the next write will block
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1263 if (!blocking)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1264 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1265 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1266 blocking = 1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1267 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1268 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1269 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1270 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1271 }
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1272 #endif
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1273
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1274 const int mouse_delays[] = {112*7, 120*7, 96*7, 132*7, 104*7, 96*7, 112*7, 96*7};
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1275
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1276 void io_data_write(io_port * port, uint8_t value, uint32_t current_cycle)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1277 {
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1278 uint8_t old_output = (port->control & port->output) | (~port->control & 0xFF);
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1279 uint8_t output = (port->control & value) | (~port->control & 0xFF);
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1280 switch (port->device_type)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1281 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1282 case IO_GAMEPAD6:
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1283 //check if TH has changed
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1284 if ((old_output & TH) ^ (output & TH)) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1285 if (current_cycle >= port->device.pad.timeout_cycle) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1286 port->device.pad.th_counter = 0;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1287 }
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1288 if (!(output & TH)) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1289 port->device.pad.th_counter++;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1290 }
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1291 port->device.pad.timeout_cycle = current_cycle + TH_TIMEOUT;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1292 }
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1293 break;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1294 case IO_MOUSE:
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1295 mouse_check_ready(port, current_cycle);
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1296 if (output & TH) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1297 //request is over or mouse is being reset
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1298 if (port->device.mouse.tr_counter) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1299 //request is over
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1300 port->device.mouse.last_read_x = port->device.mouse.latched_x;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1301 port->device.mouse.last_read_y = port->device.mouse.latched_y;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1302 }
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1303 port->device.mouse.tr_counter = 0;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1304 port->device.mouse.ready_cycle = CYCLE_NEVER;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1305 } else {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1306 if ((output & TR) != (old_output & TR)) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1307 int delay_index = port->device.mouse.tr_counter >= sizeof(mouse_delays) ? sizeof(mouse_delays)-1 : port->device.mouse.tr_counter;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1308 port->device.mouse.ready_cycle = current_cycle + mouse_delays[delay_index];
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1309 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1310 }
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1311 break;
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1312 case IO_SATURN_KEYBOARD:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1313 if (output & TH) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1314 //request is over
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1315 if (port->device.keyboard.tr_counter >= 10 && port->device.keyboard.read_pos != 0xFF) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1316 //remove scan code from buffer
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1317 port->device.keyboard.read_pos++;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1318 port->device.keyboard.read_pos &= 7;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1319 if (port->device.keyboard.read_pos == port->device.keyboard.write_pos) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1320 port->device.keyboard.read_pos = 0xFF;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1321 }
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1322 }
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1323 port->device.keyboard.tr_counter = 0;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1324 } else {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1325 if ((output & TR) != (old_output & TR)) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1326 port->device.keyboard.tr_counter++;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1327 }
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1328 }
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1329 break;
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1330 #ifndef _WIN32
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1331 case IO_GENERIC:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1332 wait_for_connection(port);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1333 port->input[IO_STATE] = IO_WRITE_PENDING;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1334 service_socket(port);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1335 break;
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1336 #endif
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1337 }
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1338 port->output = value;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1339
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1340 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1341
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1342 uint8_t io_data_read(io_port * port, uint32_t current_cycle)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1343 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1344 uint8_t control = port->control | 0x80;
911
73732ae76fa8 IO port pins should read as high from the perspective of a device when they are set as inputs
Michael Pavone <pavone@retrodev.com>
parents: 910
diff changeset
1345 uint8_t output = (control & port->output) | (~control & 0xFF);
73732ae76fa8 IO port pins should read as high from the perspective of a device when they are set as inputs
Michael Pavone <pavone@retrodev.com>
parents: 910
diff changeset
1346 uint8_t th = output & 0x40;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1347 uint8_t input;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1348 switch (port->device_type)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1349 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1350 case IO_GAMEPAD3:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1351 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1352 input = port->input[th ? GAMEPAD_TH1 : GAMEPAD_TH0];
888
bc127fa1f800 Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents: 886
diff changeset
1353 if (!th) {
bc127fa1f800 Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents: 886
diff changeset
1354 input |= 0xC;
bc127fa1f800 Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents: 886
diff changeset
1355 }
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1356 //controller output is logically inverted
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1357 input = ~input;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1358 break;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1359 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1360 case IO_GAMEPAD6:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1361 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1362 if (current_cycle >= port->device.pad.timeout_cycle) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1363 port->device.pad.th_counter = 0;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1364 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1365 /*if (port->input[GAMEPAD_TH0] || port->input[GAMEPAD_TH1]) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1366 printf("io_data_read | control: %X, TH: %X, GAMEPAD_TH0: %X, GAMEPAD_TH1: %X, TH Counter: %d, Timeout: %d, Cycle: %d\n", control, th, port->input[GAMEPAD_TH0], port->input[GAMEPAD_TH1], port->th_counter,port->timeout_cycle, context->current_cycle);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1367 }*/
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1368 if (th) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1369 if (port->device.pad.th_counter == 3) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1370 input = port->input[GAMEPAD_EXTRA];
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1371 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1372 input = port->input[GAMEPAD_TH1];
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1373 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1374 } else {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1375 if (port->device.pad.th_counter == 3) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1376 input = port->input[GAMEPAD_TH0] | 0xF;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1377 } else if(port->device.pad.th_counter == 4) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1378 input = port->input[GAMEPAD_TH0] & 0x30;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1379 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1380 input = port->input[GAMEPAD_TH0] | 0xC;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1381 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1382 }
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1383 //controller output is logically inverted
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1384 input = ~input;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1385 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1386 }
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1387 case IO_MOUSE:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1388 {
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1389 mouse_check_ready(port, current_cycle);
911
73732ae76fa8 IO port pins should read as high from the perspective of a device when they are set as inputs
Michael Pavone <pavone@retrodev.com>
parents: 910
diff changeset
1390 uint8_t tr = output & TR;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1391 if (th) {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1392 if (tr) {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1393 input = 0x10;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1394 } else {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1395 input = 0;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1396 }
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1397 } else {
913
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 912
diff changeset
1398
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1399 int16_t delta_x = port->device.mouse.latched_x - port->device.mouse.last_read_x;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1400 int16_t delta_y = port->device.mouse.last_read_y - port->device.mouse.latched_y;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1401 switch (port->device.mouse.tr_counter)
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1402 {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1403 case 0:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1404 input = 0xB;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1405 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1406 case 1:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1407 case 2:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1408 input = 0xF;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1409 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1410 case 3:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1411 input = 0;
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1412 if (delta_y > 255 || delta_y < -255) {
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1413 input |= 8;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1414 }
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1415 if (delta_x > 255 || delta_x < -255) {
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1416 input |= 4;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1417 }
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1418 if (delta_y < 0) {
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1419 input |= 2;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1420 }
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1421 if (delta_x < 0) {
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1422 input |= 1;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1423 }
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1424 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1425 case 4:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1426 input = port->input[0];
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1427 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1428 case 5:
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1429 input = delta_x >> 4 & 0xF;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1430 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1431 case 6:
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1432 input = delta_x & 0xF;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1433 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1434 case 7:
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1435 input = delta_y >> 4 & 0xF;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1436 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1437 case 8:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1438 default:
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1439 input = delta_y & 0xF;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1440 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1441 }
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1442 input |= ((port->device.mouse.tr_counter & 1) == 0) << 4;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1443 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1444 break;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1445 }
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1446 case IO_SATURN_KEYBOARD:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1447 {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1448 if (th) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1449 input = 0x11;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1450 } else {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1451 uint8_t tr = output & TR;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1452 uint16_t code = port->device.keyboard.read_pos == 0xFF ? 0
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1453 : port->device.keyboard.events[port->device.keyboard.read_pos];
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1454 switch (port->device.keyboard.tr_counter)
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1455 {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1456 case 0:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1457 input = 1;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1458 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1459 case 1:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1460 //Saturn peripheral ID
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1461 input = 3;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1462 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1463 case 2:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1464 //data size
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1465 input = 4;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1466 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1467 case 3:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1468 //d-pad
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1469 //TODO: set these based on keyboard state
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1470 input = 0xF;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1471 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1472 case 4:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1473 //Start ABC
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1474 //TODO: set these based on keyboard state
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1475 input = 0xF;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1476 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1477 case 5:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1478 //R XYZ
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1479 //TODO: set these based on keyboard state
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1480 input = 0xF;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1481 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1482 case 6:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1483 //L and KBID
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1484 //TODO: set L based on keyboard state
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1485 input = 0x8;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1486 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1487 case 7:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1488 //Capslock, Numlock, Scrolllock
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1489 //TODO: set these based on keyboard state
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1490 input = 0;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1491 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1492 case 8:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1493 input = 6;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1494 if (code & 0x100) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1495 //break
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1496 input |= 1;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1497 } else if (code) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1498 input |= 8;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1499 }
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1500 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1501 case 9:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1502 input = code >> 4 & 0xF;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1503 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1504 case 10:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1505 input = code & 0xF;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1506 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1507 case 11:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1508 input = 0;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1509 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1510 default:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1511 input = 1;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1512 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1513 }
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1514 input |= ((port->device.keyboard.tr_counter & 1) == 0) << 4;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1515 }
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1516 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1517 }
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1518 #ifndef _WIN32
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1519 case IO_SEGA_PARALLEL:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1520 if (!th)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1521 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1522 service_pipe(port);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1523 }
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1524 input = port->input[th ? IO_TH1 : IO_TH0];
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1525 break;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1526 case IO_GENERIC:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1527 if (port->input[IO_TH0] & 0x80 && port->input[IO_STATE] == IO_WRITTEN)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1528 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1529 //device requested a blocking read after writes
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1530 port->input[IO_STATE] = IO_READ_PENDING;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1531 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1532 service_socket(port);
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1533 input = port->input[IO_TH0];
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1534 break;
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1535 #endif
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1536 default:
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1537 input = 0xFF;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1538 break;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1539 }
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1540 uint8_t value = (input & (~control)) | (port->output & control);
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1541 /*if (port->input[GAMEPAD_TH0] || port->input[GAMEPAD_TH1]) {
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1542 printf ("value: %X\n", value);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1543 }*/
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1544 return value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1545 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1546
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1547