annotate io.c @ 910:c030e4af32b7

Mouse X and Y are 9-bit 2's complement not 8-bit magnitude + sign bit like I thought. Fixed mouse Y direction.
author Michael Pavone <pavone@retrodev.com>
date Sat, 05 Dec 2015 18:40:34 -0800
parents b5d35222047e
children 73732ae76fa8
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
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
23 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
24 "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
25 "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
26 "Mega Mouse",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
27 "Menacer",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
28 "Justifier",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
29 "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
30 "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
31 "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
32 "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
33 "Generic Device",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
34 "None"
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
35 };
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
36
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
37 enum {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
38 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
39 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
40 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
41 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
42 BIND_GAMEPAD3,
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
43 BIND_GAMEPAD4,
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
44 BIND_GAMEPAD5,
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
45 BIND_GAMEPAD6,
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
46 BIND_GAMEPAD7,
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
47 BIND_GAMEPAD8,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
48 BIND_MOUSE1,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
49 BIND_MOUSE2,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
50 BIND_MOUSE3,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
51 BIND_MOUSE4,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
52 BIND_MOUSE5,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
53 BIND_MOUSE6,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
54 BIND_MOUSE7,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
55 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
56 };
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
57
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
58 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
59 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
60 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
61 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
62 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
63 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
64 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
65 UI_PREV_SPEED,
444
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
66 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
67 } 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
68
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
69 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
70 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
71 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
72 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
73 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
74 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
75 } keybinding;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
76
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
77 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
78 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
79 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
80 } joydpad;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
81
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
82 typedef struct {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
83 io_port *motion_port;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
84 keybinding buttons[MAX_MOUSE_BUTTONS];
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
85 uint8_t bind_type;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
86 uint8_t motion_mode;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
87 } mousebinding;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
88
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
89 keybinding * bindings[0x10000];
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
90 keybinding * joybindings[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
91 joydpad * joydpads[MAX_JOYSTICKS];
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
92 mousebinding mice[MAX_MICE];
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
93 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
94
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
95 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
96 {
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
97 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
98 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
99 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
100 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
101 }
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
102 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
103 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
104 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
105 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
106 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
107 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
108
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
109 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
110 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
111 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
112 return;
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 if (!joybindings[joystick]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
115 int num = render_joystick_num_buttons(joystick);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
116 if (!num) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
117 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
118 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
119 joybindings[joystick] = malloc(sizeof(keybinding)*num);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
120 memset(joybindings[joystick], 0, sizeof(keybinding)*num);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
121 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
122 joybindings[joystick][button].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 joybindings[joystick][button].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 joybindings[joystick][button].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 joybindings[joystick][button].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_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
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 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
133 if (!joydpads[joystick]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
134 int num = render_joystick_num_hats(joystick);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
135 if (!num) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
136 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
137 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
138 joydpads[joystick] = malloc(sizeof(joydpad)*num);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
139 memset(joydpads[joystick], 0, sizeof(joydpad)*num);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
140 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
141 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
142 if (dpadbits[i] & direction) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
143 joydpads[joystick][dpad].bindings[i].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
144 joydpads[joystick][dpad].bindings[i].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
145 joydpads[joystick][dpad].bindings[i].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
146 joydpads[joystick][dpad].bindings[i].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
147 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
148 }
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 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
151
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
152 #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
153
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
154 #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
155 #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
156 #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
157 #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
158 #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
159 #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
160 #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
161 #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
162 #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
163 #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
164 #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
165 #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
166
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
167 #define PSEUDO_BUTTON_MOTION 0xFFFF
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
168 #define MOUSE_LEFT 1
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
169 #define MOUSE_RIGHT 2
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
170 #define MOUSE_MIDDLE 4
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
171 #define MOUSE_START 8
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
172
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
173
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
174
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
175 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
176 {
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
177
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
178 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
179 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
180 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
181 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
182 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
183 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
184
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
185 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
186 {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
187 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
188 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
189 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
190 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
191 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
192 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
193
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
194 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
195 {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
196 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
197 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
198 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
199 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
200 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
201 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
202
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
203 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
204 {
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
205 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
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
493
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
208 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
209 {
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
210 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
211 }
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
212
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
213 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
214 {
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
215 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
216 }
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
217
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
218 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
219 {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
220 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
221 {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
222 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
223 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
224 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
225 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
226 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
227 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
228 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
229 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
230 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
231 if (binding->port) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
232 binding->port->input[0] |= binding->value;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
233 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
234 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
235 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
236
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
237 void handle_keydown(int keycode)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
238 {
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
239 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
240 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
241 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
242 }
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
243 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
244 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
245 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
246 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
247
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
248 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
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 if (!joybindings[joystick]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
251 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
252 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
253 keybinding * binding = joybindings[joystick] + button;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
254 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
255 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
256
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
257 void handle_mousedown(int mouse, int button)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
258 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
259 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
260 return;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
261 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
262 keybinding * binding = mice[mouse].buttons + button - 1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
263 handle_binding_down(binding);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
264 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
265
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
266 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
267 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
268
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
269 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
270 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
271 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
272
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 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
274 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
275 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
276 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
277 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
278 case BIND_GAMEPAD2:
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
279 case BIND_GAMEPAD3:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
280 case BIND_GAMEPAD4:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
281 case BIND_GAMEPAD5:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
282 case BIND_GAMEPAD6:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
283 case BIND_GAMEPAD7:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
284 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
285 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
286 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
287 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
288 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
289 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
290 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
291 break;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
292 case BIND_MOUSE1:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
293 case BIND_MOUSE2:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
294 case BIND_MOUSE3:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
295 case BIND_MOUSE4:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
296 case BIND_MOUSE5:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
297 case BIND_MOUSE6:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
298 case BIND_MOUSE7:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
299 case BIND_MOUSE8:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
300 if (binding->port) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
301 binding->port->input[0] &= ~binding->value;
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 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
304 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
305 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
306 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
307 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
308 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
309 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
310 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
311 }
437
afbea09d7fb4 Restore one of the VDP debugging modes
Mike Pavone <pavone@retrodev.com>
parents: 432
diff changeset
312 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
313 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
314 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
315 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
316 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
317 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
318 }
722
8f5339961903 Restore the other 2 debug display modes
Michael Pavone <pavone@retrodev.com>
parents: 694
diff changeset
319 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
320 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
321 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
322 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
323 break;
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
324 case UI_SAVE_STATE:
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
325 save_state = 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
326 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
327 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
328 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
329 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
330 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
331 }
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
332 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
333 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
334 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
335 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
336 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
337 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
338 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
339 }
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
340 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
341 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
342 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
343 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
344 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
345 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
346 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
347 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
348 } 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
349 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
350 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
351 }
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
352 break;
444
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
353 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
354 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
355 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
356 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
357 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
358 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
359
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
360 void handle_keyup(int keycode)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
361 {
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
362 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
363 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
364 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
365 }
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
366 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
367 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
368 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
369 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
370
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
371 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
372 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
373 if (!joybindings[joystick]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
374 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
375 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
376 keybinding * binding = joybindings[joystick] + button;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
377 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
378 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
379
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
380 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
381 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
382 if (!joydpads[joystick]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
383 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
384 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
385 joydpad * dpad = joydpads[joystick] + dpadnum;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
386 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
387 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
388 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
389 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
390 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
391 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
392 } 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
393 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
394 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
395 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
396 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
397
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
398 void handle_mouseup(int mouse, int button)
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
399 {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
400 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
401 return;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
402 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
403 keybinding * binding = mice[mouse].buttons + button - 1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
404 handle_binding_up(binding);
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
405 }
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
406
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
407 void handle_mouse_moved(int mouse, uint16_t x, uint16_t y)
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
408 {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
409 if (mouse >= MAX_MICE || !mice[mouse].motion_port) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
410 return;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
411 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
412 //TODO: relative mode
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
413 //TODO: scale based on window size
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
414 mice[mouse].motion_port->device.mouse.cur_x = x;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
415 mice[mouse].motion_port->device.mouse.cur_y = y;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
416 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
417
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
418 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
419 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
420 const int gpadslen = strlen("gamepads.");
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
421 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
422 if (!strncmp(target, "gamepads.", gpadslen)) {
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
423 if (target[gpadslen] >= '1' && target[gpadslen] <= '8') {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
424 int padnum = target[gpadslen] - '0';
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
425 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
426 if (button) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
427 *padnum_out = padnum;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
428 *padbutton_out = button;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
429 return BIND_GAMEPAD1;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
430 } else {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
431 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
432 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
433 } 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
434 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
435 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
436 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
437 } 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
438 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
439 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
440 } else if(!strncmp(target, "mouse.", mouselen)) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
441 if (target[mouselen] >= '1' && target[mouselen] <= '8') {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
442 int mousenum = target[mouselen] - '0';
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
443 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
444 if (button) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
445 *padnum_out = mousenum;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
446 *padbutton_out = button;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
447 return BIND_MOUSE1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
448 } else {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
449 if (target[mouselen+1]) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
450 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
451 } else {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
452 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
453 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
454 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
455 } else {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
456 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
457 }
796
41f73c76b978 Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 771
diff changeset
458 } 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
459 *padbutton_out = 0;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
460 if (!strcmp(target + 3, "vdp_debug_mode")) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
461 *ui_out = UI_DEBUG_MODE_INC;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
462 } else if(!strcmp(target + 3, "vdp_debug_pal")) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
463 *ui_out = UI_DEBUG_PAL_INC;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
464 } else if(!strcmp(target + 3, "enter_debugger")) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
465 *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
466 } 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
467 *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
468 } 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
469 *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
470 *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
471 } 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
472 *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
473 } 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
474 *ui_out = UI_PREV_SPEED;
444
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
475 } 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
476 *ui_out = UI_EXIT;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
477 } 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
478 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
479 return 0;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
480 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
481 return BIND_UI;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
482 } 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
483 warning("Unrecognized binding type %s\n", target);
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
484 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
485 return 0;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
486 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
487
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
488 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
489 {
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
490 char * curstr = NULL;
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
491 int len;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
492 if (!cur) {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
493 return;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
494 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
495 char onec[2];
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
496 if (prefix) {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
497 len = strlen(prefix);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
498 curstr = malloc(len + 2);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
499 memcpy(curstr, prefix, len);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
500 } else {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
501 curstr = onec;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
502 len = 0;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
503 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
504 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
505 curstr[len+1] = 0;
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
506 if (cur->el) {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
507 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
508 } else {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
509 int keycode = tern_find_int(special, curstr, 0);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
510 if (!keycode) {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
511 keycode = curstr[0];
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
512 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
513 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
514 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
515 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
516 char * target = cur->straight.value.ptrval;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
517 int ui_func, padnum, button;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
518 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
519 if (bindtype == BIND_GAMEPAD1) {
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
520 bind_gamepad(keycode, padnum, button);
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
521 } 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
522 bind_ui(keycode, ui_func, button);
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
523 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
524 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
525 process_keys(cur->left, special, padbuttons, mousebuttons, prefix);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
526 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
527 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
528 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
529 }
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
530 }
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
531
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
532 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
533 {
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
534 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
535 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
536 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
537 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
538 }
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 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
540 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
541 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
542 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
543 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
544 } 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
545 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
546 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
547 }
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
548 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
549 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
550 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
551 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
552 } 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
553 int speed_index = atoi(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
554 if (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
555 if (!strcmp(curstr, "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
556 warning("Speed index 0 cannot be set to a custom value\n");
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
557 } 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
558 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
559 }
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
560 } 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
561 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
562 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
563 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
564 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
565 }
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
566 }
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
567 speeds[speed_index] = atoi(cur->straight.value.ptrval);
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
568 }
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
569 }
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
570 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
571 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
572 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
573 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
574 }
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
575 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
576
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
577 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
578 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
579 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
580 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
581 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
582 return;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
583 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
584
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
585 const int gamepad_len = strlen("gamepad");
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
586 const int mouse_len = strlen("mouse");
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
587 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
588 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
589 if (
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
590 (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
591 || 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
592 || 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
593 )
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
594 {
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
595 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
596 } 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
597 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
598 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
599 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
600 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
601 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
602 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
603 } else if(!strncmp(device_type, "mouse", mouse_len)) {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
604 port->device_type = IO_MOUSE;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
605 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
606 port->device.mouse.last_read_x = 0;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
607 port->device.mouse.last_read_y = 0;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
608 port->device.mouse.cur_x = 0;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
609 port->device.mouse.cur_y = 0;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
610 port->device.mouse.tr_counter = 0;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
611 } 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
612 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
613 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
614 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
615 } 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
616 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
617 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
618 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
619 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
620 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
621
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
622 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
623 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
624 switch (i)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
625 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
626 case 0:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
627 return "1";
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
628 case 1:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
629 return "2";
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
630 case 2:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
631 return "EXT";
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
632 default:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
633 return "invalid";
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
634 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
635 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
636
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
637 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
638 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
639 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
640 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
641 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
642
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
643 void setup_io_devices(tern_node * config, io_port * ports)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
644 {
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
645 tern_node *io_nodes = tern_get_node(tern_find_path(config, "io\0devices\0"));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
646 char * io_1 = tern_find_ptr(io_nodes, "1");
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
647 char * io_2 = tern_find_ptr(io_nodes, "2");
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
648 char * io_ext = tern_find_ptr(io_nodes, "ext");
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
649
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
650 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
651 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
652 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
653
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
654 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
655 {
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
656 #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
657 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
658 {
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
659 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
660 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
661 {
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
662 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
663 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
664 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
665 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
666 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
667 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
668 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
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 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
671 {
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
672 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
673 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
674 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
675 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
676 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
677 {
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
678 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
679 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
680 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
681 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
682 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
683 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
684 } 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
685 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
686 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
687 {
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
688 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
689 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
690 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
691 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
692 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
693 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
694 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
695 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
696 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
697 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
698 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
699 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
700 {
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
701 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
702 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
703 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
704 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
705 {
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
706 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
707 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
708 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
709 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
710 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
711 continue;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
712 cleanup_sockfile:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
713 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
714 cleanup_sock:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
715 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
716 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
717 }
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
718 } else
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
719 #endif
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
720 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
721 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
722 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
723 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
724 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
725 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
726 }
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 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
729 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
730 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
731 {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
732 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
733 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
734 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
735 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
736 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
737 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
738 || 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
739 && 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
740 )
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
741 {
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
742 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
743 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
744 break;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
745 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
746 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
747 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
748 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
749 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
750 int num = bindings[i].bind_type - BIND_MOUSE1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
751 for (int j = 0; j < 3; j++)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
752 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
753 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
754 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
755 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
756 bindings[i].port = ports + j;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
757 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
758 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
759 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
760 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
761 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
762 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
763
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
764 typedef struct {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
765 tern_node *padbuttons;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
766 tern_node *mousebuttons;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
767 int mouseidx;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
768 } pmb_state;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
769
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
770 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
771 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
772 pmb_state *state = data;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
773 int buttonnum = atoi(buttonstr);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
774 if (buttonnum < 1 || buttonnum > MAX_MOUSE_BUTTONS) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
775 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
776 return;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
777 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
778 buttonnum--;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
779 int ui_func, devicenum, button;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
780 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
781 switch (bindtype)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
782 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
783 case BIND_UI:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
784 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
785 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
786 case BIND_GAMEPAD1:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
787 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
788 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
789 mice[state->mouseidx].buttons[buttonnum].value = button & 0xFF;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
790 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
791 case BIND_MOUSE1:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
792 mice[state->mouseidx].buttons[buttonnum].value = button & 0xFF;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
793 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
794 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
795 if (bindtype != BIND_UI) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
796 bindtype += devicenum-1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
797 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
798 mice[state->mouseidx].buttons[buttonnum].bind_type = bindtype;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
799
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
800 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
801
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
802 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
803 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
804 tern_node **buttonmaps = data;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
805 tern_node *mousedef = tern_get_node(value);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
806 tern_node *padbuttons = buttonmaps[0];
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
807 tern_node *mousebuttons = buttonmaps[1];
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
808
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
809 if (!mousedef) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
810 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
811 return;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
812 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
813 int mouseidx = atoi(mousenum);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
814 if (mouseidx < 0 || mouseidx >= MAX_MICE) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
815 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
816 return;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
817 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
818 char *motion = tern_find_ptr(mousedef, "motion");
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
819 if (motion) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
820 int ui_func,devicenum,button;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
821 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
822 if (bindtype != BIND_UI) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
823 bindtype += devicenum-1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
824 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
825 if (button == PSEUDO_BUTTON_MOTION) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
826 mice[mouseidx].bind_type = bindtype;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
827 } else {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
828 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
829 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
830 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
831 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
832 if (buttons) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
833 pmb_state state = {padbuttons, mousebuttons, mouseidx};
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
834 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
835 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
836 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
837
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
838 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
839 {
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
840 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
841 special = tern_insert_int(special, "down", RENDERKEY_DOWN);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
842 special = tern_insert_int(special, "left", RENDERKEY_LEFT);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
843 special = tern_insert_int(special, "right", RENDERKEY_RIGHT);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
844 special = tern_insert_int(special, "enter", '\r');
504
7b0df1aaf384 Add support for left and right shift keys
Mike Pavone <pavone@retrodev.com>
parents: 493
diff changeset
845 special = tern_insert_int(special, "esc", RENDERKEY_ESC);
7b0df1aaf384 Add support for left and right shift keys
Mike Pavone <pavone@retrodev.com>
parents: 493
diff changeset
846 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
847 special = tern_insert_int(special, "rshift", RENDERKEY_RSHIFT);
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
848 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
849 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
850 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
851 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
852
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
853 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
854 padbuttons = tern_insert_int(padbuttons, ".down", DPAD_DOWN);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
855 padbuttons = tern_insert_int(padbuttons, ".left", DPAD_LEFT);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
856 padbuttons = tern_insert_int(padbuttons, ".right", DPAD_RIGHT);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
857 padbuttons = tern_insert_int(padbuttons, ".a", BUTTON_A);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
858 padbuttons = tern_insert_int(padbuttons, ".b", BUTTON_B);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
859 padbuttons = tern_insert_int(padbuttons, ".c", BUTTON_C);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
860 padbuttons = tern_insert_int(padbuttons, ".x", BUTTON_X);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
861 padbuttons = tern_insert_int(padbuttons, ".y", BUTTON_Y);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
862 padbuttons = tern_insert_int(padbuttons, ".z", BUTTON_Z);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
863 padbuttons = tern_insert_int(padbuttons, ".start", BUTTON_START);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
864 padbuttons = tern_insert_int(padbuttons, ".mode", BUTTON_MODE);
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
865
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
866 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
867 mousebuttons = tern_insert_int(mousebuttons, ".middle", MOUSE_MIDDLE);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
868 mousebuttons = tern_insert_int(mousebuttons, ".right", MOUSE_RIGHT);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
869 mousebuttons = tern_insert_int(mousebuttons, ".start", MOUSE_START);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
870 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
871
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
872 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
873 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
874 char numstr[] = "00";
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
875 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
876 if (pads) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
877 for (int i = 0; i < 100 && i < render_num_joysticks(); i++)
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
878 {
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
879
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
880 if (i < 10) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
881 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
882 numstr[1] = 0;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
883 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
884 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
885 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
886 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
887 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
888 if (pad) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
889 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
890 if (dpad_node) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
891 for (int dpad = 0; dpad < 10 && dpad < render_joystick_num_hats(i); dpad++)
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
892 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
893 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
894 numstr[1] = 0;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
895 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
896 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
897 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
898 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
899 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
900 if (target) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
901 int ui_func, padnum, button;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
902 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
903 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
904 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
905 } 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
906 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
907 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
908 }
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
909 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
910 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
911 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
912 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
913 if (button_node) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
914 for (int but = 0; but < 100 && but < render_joystick_num_buttons(i); but++)
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
915 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
916 if (but < 10) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
917 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
918 numstr[1] = 0;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
919 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
920 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
921 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
922 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
923 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
924 if (target) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
925 int ui_func, padnum, button;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
926 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
927 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
928 bind_button_gamepad(i, but, padnum, button);
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
929 } 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
930 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
931 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
932 }
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
933 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
934 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
935 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
936 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
937 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
938 memset(mice, 0, sizeof(mice));
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
939 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
940 if (mice) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
941 tern_node *buttonmaps[2] = {padbuttons, mousebuttons};
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
942 tern_foreach(mice, process_mouse, buttonmaps);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
943 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
944 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
945 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
946 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
947 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
948 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
949 {
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
950 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
951 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
952 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
953 }
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
954 }
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
955 map_all_bindings(ports);
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
956 }
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
957
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
958 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
959 {
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
960 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
961 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
962 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
963 {
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
964 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
965 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
966 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
967 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
968 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
969 if (joybindings[stick])
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
970 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
971 int numbuttons = render_joystick_num_buttons(stick);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
972 map_bindings(ports, joybindings[stick], render_joystick_num_buttons(stick));
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
973 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
974 if (joydpads[stick])
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
975 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
976 map_bindings(ports, joydpads[stick]->bindings, 4);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
977 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
978 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
979 for (int mouse = 0; mouse < MAX_MICE; mouse++)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
980 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
981 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
982 int num = mice[mouse].bind_type - BIND_MOUSE1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
983 for (int j = 0; j < 3; j++)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
984 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
985 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
986 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
987 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
988 mice[mouse].motion_port = ports + j;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
989 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
990 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
991 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
992 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
993 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
994 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
995 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
996
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
997 #define TH 0x40
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
998 #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
999 #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
1000
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1001 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
1002 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1003 /*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
1004 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
1005 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
1006 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
1007 }*/
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1008 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
1009 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1010 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
1011 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1012 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
1013 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1014 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
1015 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1016 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1017 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1018
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1019 #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
1020 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
1021 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1022 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
1023 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1024 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
1025 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
1026 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
1027 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1028 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1029
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1030 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
1031 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1032 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
1033 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
1034 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
1035 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1036 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
1037 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
1038 } 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
1039 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
1040 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1041 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1042
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1043 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
1044 {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1045 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
1046 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
1047 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
1048 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
1049 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1050 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
1051 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
1052 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1053 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
1054 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
1055 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1056 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
1057 if (blocking)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1058 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1059 //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
1060 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
1061 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1062 } 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
1063 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
1064 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1065 } 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
1066 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
1067 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
1068 } 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
1069 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
1070 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
1071 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
1072 } 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
1073 //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
1074 if (!blocking)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1075 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1076 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
1077 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
1078 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1079 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1080 //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
1081 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
1082 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1083 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1084
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1085 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
1086 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1087 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
1088 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
1089 blocking = 0;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1090 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
1091 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1092 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
1093 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
1094 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1095 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
1096 if (blocking)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1097 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1098 //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
1099 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
1100 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1101 } 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
1102 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
1103 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
1104 } 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
1105 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
1106 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
1107 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
1108 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1109 //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
1110 if (!blocking)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1111 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1112 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
1113 blocking = 1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1114 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1115 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1116 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1117 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1118 }
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1119 #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
1120
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1121 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
1122 {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1123 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
1124 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1125 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
1126 if (port->control & TH) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1127 //check if TH has changed
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1128 if ((port->output & TH) ^ (value & TH)) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1129 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
1130 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
1131 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1132 if (!(value & TH)) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1133 port->device.pad.th_counter++;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1134 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1135 port->device.pad.timeout_cycle = current_cycle + TH_TIMEOUT;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1136 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1137 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1138 port->output = value;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1139 break;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1140 case IO_MOUSE:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1141 if ((port->control & (TH|TR)) == (TH|TR)) {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1142 if (!(value & TH) && (value & TR) != (port->output & TR)) {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1143 port->device.mouse.tr_counter++;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1144 }
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1145 } else {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1146 port->device.mouse.tr_counter = 0;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1147 }
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1148 port->output = value;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1149 break;
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1150 #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
1151 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
1152 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
1153 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
1154 port->output = value;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1155 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
1156 break;
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1157 #endif
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1158 default:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1159 port->output = value;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1160 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1161
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1162 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1163
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1164 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
1165 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1166 uint8_t control = port->control | 0x80;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1167 uint8_t th = control & port->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
1168 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
1169 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
1170 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1171 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
1172 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1173 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
1174 if (!th) {
bc127fa1f800 Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents: 886
diff changeset
1175 input |= 0xC;
bc127fa1f800 Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents: 886
diff changeset
1176 }
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1177 //controller output is logically inverted
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1178 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
1179 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
1180 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1181 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
1182 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1183 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
1184 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
1185 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1186 /*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
1187 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
1188 }*/
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1189 if (th) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1190 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
1191 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
1192 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1193 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
1194 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1195 } else {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1196 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
1197 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
1198 } 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
1199 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
1200 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1201 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
1202 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1203 }
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1204 //controller output is logically inverted
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1205 input = ~input;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1206 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1207 }
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1208 case IO_MOUSE:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1209 {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1210 uint8_t tr = control & port->output & TR;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1211 if (th) {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1212 if (tr) {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1213 input = 0x10;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1214 } else {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1215 input = 0;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1216 }
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1217 } else {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1218 switch (port->device.mouse.tr_counter)
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1219 {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1220 case 0:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1221 input = 0xB;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1222 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1223 case 1:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1224 case 2:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1225 input = 0xF;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1226 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1227 case 3:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1228 input = 0;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1229 //it would be unfortunate if our event handler updated cur_x or cur_y in the middle
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1230 //of the mouse poll sequence, so we save the delta here
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1231 port->device.mouse.delta_x = port->device.mouse.cur_x - port->device.mouse.last_read_x;
910
c030e4af32b7 Mouse X and Y are 9-bit 2's complement not 8-bit magnitude + sign bit like I thought. Fixed mouse Y direction.
Michael Pavone <pavone@retrodev.com>
parents: 907
diff changeset
1232 port->device.mouse.delta_y = port->device.mouse.last_read_y - port->device.mouse.cur_y;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1233 if (port->device.mouse.delta_y > 255 || port->device.mouse.delta_y < -255) {
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1234 input |= 8;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1235 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1236 if (port->device.mouse.delta_x > 255 || port->device.mouse.delta_x < -255) {
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1237 input |= 4;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1238 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1239 if (port->device.mouse.delta_y < 0) {
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1240 input |= 2;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1241 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1242 if (port->device.mouse.delta_x < 0) {
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1243 input |= 1;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1244 }
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1245 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1246 case 4:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1247 input = port->input[0];
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1248 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1249 case 5:
910
c030e4af32b7 Mouse X and Y are 9-bit 2's complement not 8-bit magnitude + sign bit like I thought. Fixed mouse Y direction.
Michael Pavone <pavone@retrodev.com>
parents: 907
diff changeset
1250 input = port->device.mouse.delta_x >> 4 & 0xF;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1251 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1252 case 6:
910
c030e4af32b7 Mouse X and Y are 9-bit 2's complement not 8-bit magnitude + sign bit like I thought. Fixed mouse Y direction.
Michael Pavone <pavone@retrodev.com>
parents: 907
diff changeset
1253 input = port->device.mouse.delta_x & 0xF;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1254 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1255 case 7:
910
c030e4af32b7 Mouse X and Y are 9-bit 2's complement not 8-bit magnitude + sign bit like I thought. Fixed mouse Y direction.
Michael Pavone <pavone@retrodev.com>
parents: 907
diff changeset
1256 input = port->device.mouse.delta_y >> 4 & 0xF;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1257 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1258 case 8:
910
c030e4af32b7 Mouse X and Y are 9-bit 2's complement not 8-bit magnitude + sign bit like I thought. Fixed mouse Y direction.
Michael Pavone <pavone@retrodev.com>
parents: 907
diff changeset
1259 input = port->device.mouse.delta_y & 0xF;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1260 //need to figure out when this actually happens
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1261 port->device.mouse.last_read_x = port->device.mouse.cur_x;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1262 port->device.mouse.last_read_y = port->device.mouse.cur_y;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1263 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1264 default:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1265 //need to test what happens here
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1266 input = 0;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1267 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1268 }
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1269 input |= tr >> 1;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1270 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1271 break;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1272 }
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1273 #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
1274 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
1275 if (!th)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1276 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1277 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
1278 }
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1279 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
1280 break;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1281 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
1282 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
1283 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1284 //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
1285 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
1286 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1287 service_socket(port);
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1288 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
1289 break;
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1290 #endif
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1291 default:
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1292 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
1293 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
1294 }
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1295 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
1296 /*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
1297 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
1298 }*/
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1299 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
1300 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1301
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1302