Mercurial > repos > blastem
annotate io.c @ 1877:9486236f28ac
Fix sprite rendering regression introduced by H40 line at a time optimization
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 20 Aug 2019 07:07:31 -0700 |
parents | 52a47611a273 |
children | e7a516f08cec |
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 |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
18 #include "serialize.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
|
19 #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
|
20 #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
|
21 #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
|
22 #include "util.h" |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
23 #include "bindings.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
|
24 |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
25 #define CYCLE_NEVER 0xFFFFFFFF |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
26 #define MIN_POLL_INTERVAL 6840 |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
27 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
28 const char * device_type_names[] = { |
1650
d6c403135e64
Re-order IO device type enum so "None" is selected when no device is specified for a port
Michael Pavone <pavone@retrodev.com>
parents:
1610
diff
changeset
|
29 "None", |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
30 "SMS gamepad", |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
31 "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
|
32 "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
|
33 "Mega Mouse", |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
34 "Saturn Keyboard", |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
35 "XBAND Keyboard", |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
36 "Menacer", |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
37 "Justifier", |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
38 "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
|
39 "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
|
40 "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
|
41 "Sega Parallel Transfer Board", |
1650
d6c403135e64
Re-order IO device type enum so "None" is selected when no device is specified for a port
Michael Pavone <pavone@retrodev.com>
parents:
1610
diff
changeset
|
42 "Generic Device" |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
43 }; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
44 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
45 #define GAMEPAD_TH0 0 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
46 #define GAMEPAD_TH1 1 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
47 #define GAMEPAD_EXTRA 2 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
48 #define GAMEPAD_NONE 0xF |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
50 #define IO_TH0 0 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
51 #define IO_TH1 1 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
52 #define IO_STATE 2 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
54 enum { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
55 IO_WRITE_PENDING, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
56 IO_WRITTEN, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
57 IO_READ_PENDING, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
58 IO_READ |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
59 }; |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
60 |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
61 typedef struct { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
62 uint8_t states[2], value; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
63 } gp_button_def; |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
64 |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
65 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
66 static gp_button_def button_defs[NUM_GAMEPAD_BUTTONS] = { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
67 [DPAD_UP] = {.states = {GAMEPAD_TH0, GAMEPAD_TH1}, .value = 0x1}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
68 [DPAD_DOWN] = {.states = {GAMEPAD_TH0, GAMEPAD_TH1}, .value = 0x2}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
69 [DPAD_LEFT] = {.states = {GAMEPAD_TH1, GAMEPAD_NONE}, .value = 0x4}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
70 [DPAD_RIGHT] = {.states = {GAMEPAD_TH1, GAMEPAD_NONE}, .value = 0x8}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
71 [BUTTON_A] = {.states = {GAMEPAD_TH0, GAMEPAD_NONE}, .value = 0x10}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
72 [BUTTON_B] = {.states = {GAMEPAD_TH1, GAMEPAD_NONE}, .value = 0x10}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
73 [BUTTON_C] = {.states = {GAMEPAD_TH1, GAMEPAD_NONE}, .value = 0x20}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
74 [BUTTON_START] = {.states = {GAMEPAD_TH0, GAMEPAD_NONE}, .value = 0x20}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
75 [BUTTON_X] = {.states = {GAMEPAD_EXTRA, GAMEPAD_NONE}, .value = 0x4}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
76 [BUTTON_Y] = {.states = {GAMEPAD_EXTRA, GAMEPAD_NONE}, .value = 0x2}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
77 [BUTTON_Z] = {.states = {GAMEPAD_EXTRA, GAMEPAD_NONE}, .value = 0x1}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
78 [BUTTON_MODE] = {.states = {GAMEPAD_EXTRA, GAMEPAD_NONE}, .value = 0x8}, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
79 }; |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
80 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
81 static io_port *find_gamepad(sega_io *io, uint8_t gamepad_num) |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
82 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
83 for (int i = 0; i < 3; i++) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
84 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
85 io_port *port = io->ports + i; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
86 if (port->device_type < IO_MOUSE && port->device.pad.gamepad_num == gamepad_num) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
87 return port; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
88 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
89 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
90 return NULL; |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
91 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
92 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
93 static io_port *find_mouse(sega_io *io, uint8_t mouse_num) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
95 for (int i = 0; i < 3; i++) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
96 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
97 io_port *port = io->ports + i; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
98 if (port->device_type == IO_MOUSE && port->device.mouse.mouse_num == mouse_num) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
99 return port; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
100 } |
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 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
102 return NULL; |
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 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
105 static io_port *find_keyboard(sega_io *io) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
107 for (int i = 0; i < 3; i++) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
108 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
109 io_port *port = io->ports + i; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
110 if (port->device_type == IO_SATURN_KEYBOARD || port->device_type == IO_XBAND_KEYBOARD) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
111 return port; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
112 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
114 return NULL; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 |
1610 | 117 void io_port_gamepad_down(io_port *port, uint8_t button) |
118 { | |
119 gp_button_def *def = button_defs + button; | |
120 port->input[def->states[0]] |= def->value; | |
121 if (def->states[1] != GAMEPAD_NONE) { | |
122 port->input[def->states[1]] |= def->value; | |
123 } | |
124 } | |
125 | |
126 void io_port_gamepad_up(io_port *port, uint8_t button) | |
127 { | |
128 gp_button_def *def = button_defs + button; | |
129 port->input[def->states[0]] &= ~def->value; | |
130 if (def->states[1] != GAMEPAD_NONE) { | |
131 port->input[def->states[1]] &= ~def->value; | |
132 } | |
133 } | |
134 | |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
135 void io_gamepad_down(sega_io *io, uint8_t gamepad_num, uint8_t button) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
137 io_port *port = find_gamepad(io, gamepad_num); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
138 if (port) { |
1610 | 139 io_port_gamepad_down(port, button); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
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 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
143 void io_gamepad_up(sega_io *io, uint8_t gamepad_num, uint8_t button) |
1194
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
144 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
145 io_port *port = find_gamepad(io, gamepad_num); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
146 if (port) { |
1610 | 147 io_port_gamepad_up(port, button); |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
148 } |
1194
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
149 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
150 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
151 void io_mouse_down(sega_io *io, uint8_t mouse_num, uint8_t button) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
153 io_port *port = find_mouse(io, mouse_num); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
154 if (port) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
155 port->input[0] |= button; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
159 void io_mouse_up(sega_io *io, uint8_t mouse_num, uint8_t button) |
493
36c080ece4ed
Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents:
483
diff
changeset
|
160 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
161 io_port *port = find_mouse(io, mouse_num); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
162 if (port) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
163 port->input[0] &= ~button; |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
164 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
167 void io_mouse_motion_absolute(sega_io *io, uint8_t mouse_num, uint16_t x, uint16_t y) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
168 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
169 io_port *port = find_mouse(io, mouse_num); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
170 if (port) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
171 port->device.mouse.cur_x = x; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
172 port->device.mouse.cur_y = y; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
173 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
174 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
175 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
176 void io_mouse_motion_relative(sega_io *io, uint8_t mouse_num, int32_t x, int32_t y) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
177 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
178 io_port *port = find_mouse(io, mouse_num); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
179 if (port) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
180 port->device.mouse.cur_x += x; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
181 port->device.mouse.cur_y += y; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
182 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
183 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
184 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
185 void store_key_event(io_port *keyboard_port, uint16_t code) |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
186 { |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
187 if (keyboard_port && keyboard_port->device.keyboard.write_pos != keyboard_port->device.keyboard.read_pos) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
188 //there's room in the buffer, record this event |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
189 keyboard_port->device.keyboard.events[keyboard_port->device.keyboard.write_pos] = code; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
190 if (keyboard_port->device.keyboard.read_pos == 0xFF) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
191 //ring buffer was empty, update read_pos to indicate there is now data |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
192 keyboard_port->device.keyboard.read_pos = keyboard_port->device.keyboard.write_pos; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
193 } |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
194 keyboard_port->device.keyboard.write_pos = (keyboard_port->device.keyboard.write_pos + 1) & 7; |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
195 } |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
196 } |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
197 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
198 void io_keyboard_down(sega_io *io, uint8_t scancode) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
200 store_key_event(find_keyboard(io), scancode); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
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 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
203 void io_keyboard_up(sega_io *io, uint8_t scancode) |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
204 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
205 store_key_event(find_keyboard(io), 0xF000 | scancode); |
1576
2b132d894d76
Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
206 } |
2b132d894d76
Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
207 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
208 uint8_t io_has_keyboard(sega_io *io) |
431
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
209 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
210 return find_keyboard(io) != NULL; |
431
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
211 } |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
212 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
213 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
|
214 { |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
215 //assuming that the io_port struct has been zeroed if this is the first time this has been called |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
216 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
|
217 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
218 return; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
219 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
220 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
221 const int gamepad_len = strlen("gamepad"); |
1783 | 222 if (startswith(device_type, "gamepad")) |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
223 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
224 if ( |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
225 (device_type[gamepad_len] != '3' && device_type[gamepad_len] != '6' && device_type[gamepad_len] != '2') |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
226 || 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
|
227 || device_type[gamepad_len+2] > '8' || device_type[gamepad_len+3] != 0 |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
228 ) { |
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
|
229 warning("%s is not a valid gamepad type\n", device_type); |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
230 } else if (device_type[gamepad_len] == '3') { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
231 port->device_type = IO_GAMEPAD3; |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
232 } else if (device_type[gamepad_len] == '2') { |
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
233 port->device_type = IO_GAMEPAD2; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
234 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
235 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
|
236 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
237 port->device.pad.gamepad_num = device_type[gamepad_len+2] - '0'; |
1783 | 238 } else if(startswith(device_type, "mouse")) { |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
239 if (port->device_type != IO_MOUSE) { |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
240 port->device_type = IO_MOUSE; |
1783 | 241 port->device.mouse.mouse_num = device_type[strlen("mouse")+1] - '0'; |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
242 port->device.mouse.last_read_x = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
243 port->device.mouse.last_read_y = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
244 port->device.mouse.cur_x = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
245 port->device.mouse.cur_y = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
246 port->device.mouse.latched_x = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
247 port->device.mouse.latched_y = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
248 port->device.mouse.ready_cycle = CYCLE_NEVER; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
249 port->device.mouse.tr_counter = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
250 } |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
251 } else if(!strcmp(device_type, "saturn keyboard")) { |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
252 if (port->device_type != IO_SATURN_KEYBOARD) { |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
253 port->device_type = IO_SATURN_KEYBOARD; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
254 port->device.keyboard.read_pos = 0xFF; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
255 port->device.keyboard.write_pos = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
256 } |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
257 } else if(!strcmp(device_type, "xband keyboard")) { |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
258 if (port->device_type != IO_XBAND_KEYBOARD) { |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
259 port->device_type = IO_XBAND_KEYBOARD; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
260 port->device.keyboard.read_pos = 0xFF; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
261 port->device.keyboard.write_pos = 0; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
262 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
263 } else if(!strcmp(device_type, "sega_parallel")) { |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
264 if (port->device_type != IO_SEGA_PARALLEL) { |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
265 port->device_type = IO_SEGA_PARALLEL; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
266 port->device.stream.data_fd = -1; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
267 port->device.stream.listen_fd = -1; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
268 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
269 } else if(!strcmp(device_type, "generic")) { |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
270 if (port->device_type != IO_GENERIC) { |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
271 port->device_type = IO_GENERIC; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
272 port->device.stream.data_fd = -1; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
273 port->device.stream.listen_fd = -1; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
274 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
275 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
276 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
277 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
278 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
|
279 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
280 switch (i) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
281 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
282 case 0: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
283 return "1"; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
284 case 1: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
285 return "2"; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
286 case 2: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
287 return "EXT"; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
288 default: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
289 return "invalid"; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
290 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
291 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
292 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
293 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
|
294 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
|
295 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
296 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
|
297 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
298 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
299 void setup_io_devices(tern_node * config, rom_info *rom, sega_io *io) |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
300 { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
301 io_port * ports = io->ports; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1294
diff
changeset
|
302 tern_node *io_nodes = tern_find_path(config, "io\0devices\0", TVAL_NODE).ptrval; |
1689
7f42a93f18a4
Have a suitable default IO port configuration when nonIO is present from the config file. Fixed off by one in processing gamepad button events in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1650
diff
changeset
|
303 char * io_1 = rom->port1_override ? rom->port1_override : tern_find_ptr_default(io_nodes, "1", "gamepad6.1"); |
7f42a93f18a4
Have a suitable default IO port configuration when nonIO is present from the config file. Fixed off by one in processing gamepad button events in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1650
diff
changeset
|
304 char * io_2 = rom->port2_override ? rom->port2_override : tern_find_ptr_default(io_nodes, "2", "gamepad6.2"); |
7f42a93f18a4
Have a suitable default IO port configuration when nonIO is present from the config file. Fixed off by one in processing gamepad button events in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1650
diff
changeset
|
305 char * io_ext = rom->ext_override ? rom->ext_override : tern_find_ptr(io_nodes, "ext"); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
306 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
307 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
|
308 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
|
309 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
|
310 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
311 uint8_t mouse_mode; |
1396
aca496957999
Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
312 if (ports[0].device_type == IO_MOUSE || ports[1].device_type == IO_MOUSE || ports[2].device_type == IO_MOUSE) { |
aca496957999
Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
313 if (render_fullscreen()) { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
314 mouse_mode = MOUSE_RELATIVE; |
1396
aca496957999
Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
315 } else { |
aca496957999
Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
316 if (rom->mouse_mode && !strcmp(rom->mouse_mode, "absolute")) { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
317 mouse_mode = MOUSE_ABSOLUTE; |
1396
aca496957999
Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
318 } else { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
319 mouse_mode = MOUSE_CAPTURE; |
1396
aca496957999
Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
320 } |
aca496957999
Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
321 } |
916
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
322 } else { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
323 mouse_mode = MOUSE_NONE; |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
324 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
325 bindings_set_mouse_mode(mouse_mode); |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
326 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
327 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
|
328 { |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
329 #ifndef _WIN32 |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
330 if (ports[i].device_type == IO_SEGA_PARALLEL && ports[i].device.stream.data_fd == -1) |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
331 { |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1294
diff
changeset
|
332 char *pipe_name = tern_find_path(config, "io\0parallel_pipe\0", TVAL_PTR).ptrval; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
333 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
|
334 { |
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
|
335 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
|
336 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
|
337 } else { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1791
diff
changeset
|
338 debug_message("IO port: %s connected to device '%s' with pipe name: %s\n", io_name(i), device_type_names[ports[i].device_type], pipe_name); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
339 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
|
340 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
341 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
|
342 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
343 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
|
344 { |
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
|
345 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
|
346 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
|
347 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
348 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
|
349 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
|
350 { |
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
|
351 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
|
352 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
|
353 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
354 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
355 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
356 } |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
357 } else if (ports[i].device_type == IO_GENERIC && ports[i].device.stream.data_fd == -1) { |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1294
diff
changeset
|
358 char *sock_name = tern_find_path(config, "io\0socket\0", TVAL_PTR).ptrval; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
359 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
|
360 { |
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
|
361 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
|
362 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
|
363 } else { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1791
diff
changeset
|
364 debug_message("IO port: %s connected to device '%s' with socket name: %s\n", io_name(i), device_type_names[ports[i].device_type], sock_name); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
365 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
|
366 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
|
367 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
|
368 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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 { |
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
|
374 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
|
375 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
|
376 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
377 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
|
378 { |
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
|
379 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
|
380 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
|
381 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
382 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
|
383 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
|
384 continue; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
385 cleanup_sockfile: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
386 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
|
387 cleanup_sock: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
388 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
|
389 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
|
390 } |
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
|
391 } else |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
392 #endif |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
393 if (ports[i].device_type == IO_GAMEPAD3 || ports[i].device_type == IO_GAMEPAD6 || ports[i].device_type == IO_GAMEPAD2) { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1791
diff
changeset
|
394 debug_message("IO port %s connected to gamepad #%d with type '%s'\n", io_name(i), ports[i].device.pad.gamepad_num, device_type_names[ports[i].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
|
395 } else { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1791
diff
changeset
|
396 debug_message("IO port %s connected to device '%s'\n", io_name(i), device_type_names[ports[i].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
|
397 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
398 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
399 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
400 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
401 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
402 #define TH 0x40 |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
403 #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
|
404 #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
|
405 |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
406 void mouse_check_ready(io_port *port, uint32_t current_cycle) |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
407 { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
408 if (current_cycle >= port->device.mouse.ready_cycle) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
409 port->device.mouse.tr_counter++; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
410 port->device.mouse.ready_cycle = CYCLE_NEVER; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
411 if (port->device.mouse.tr_counter == 3) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
412 port->device.mouse.latched_x = port->device.mouse.cur_x; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
413 port->device.mouse.latched_y = port->device.mouse.cur_y; |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
414 /* FIXME mouse mode owned by bindings now |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
415 if (current_io->mouse_mode == MOUSE_ABSOLUTE) { |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
416 //avoid overflow in absolute mode |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
417 int deltax = port->device.mouse.latched_x - port->device.mouse.last_read_x; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
418 if (abs(deltax) > 255) { |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
419 port->device.mouse.latched_x = port->device.mouse.last_read_x + (deltax > 0 ? 255 : -255); |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
420 } |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
421 int deltay = port->device.mouse.latched_y - port->device.mouse.last_read_y; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
422 if (abs(deltay) > 255) { |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
423 port->device.mouse.latched_y = port->device.mouse.last_read_y + (deltay > 0 ? 255 : -255); |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
424 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
425 }*/ |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
426 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
427 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
428 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
429 |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
430 uint32_t last_poll_cycle; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
431 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
|
432 { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
433 /*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
|
434 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
|
435 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
|
436 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
|
437 }*/ |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
438 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
|
439 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
440 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
|
441 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
442 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
|
443 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
444 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
|
445 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
446 } else if (port->device_type == IO_MOUSE) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
447 mouse_check_ready(port, current_cycle); |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
448 if (port->device.mouse.ready_cycle != CYCLE_NEVER) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
449 port->device.mouse.ready_cycle -= deduction; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
450 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
451 } |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
452 for (int i = 0; i < 8; i++) |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
453 { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
454 if (port->slow_rise_start[i] != CYCLE_NEVER) { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
455 if (port->slow_rise_start[i] >= deduction) { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
456 port->slow_rise_start[i] -= deduction; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
457 } else { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
458 port->slow_rise_start[i] = CYCLE_NEVER; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
459 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
460 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
461 } |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
462 if (last_poll_cycle >= deduction) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
463 last_poll_cycle -= deduction; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
464 } else { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
465 last_poll_cycle = 0; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
466 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
467 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
468 |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
469 #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
|
470 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
|
471 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
472 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
|
473 { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1791
diff
changeset
|
474 debug_message("Waiting for socket connection..."); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
475 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
|
476 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
|
477 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
478 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
479 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
480 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
|
481 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
482 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
|
483 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
|
484 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
|
485 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
486 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
|
487 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
|
488 } 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
|
489 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
|
490 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
491 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
492 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
493 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
|
494 { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
495 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
|
496 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
|
497 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
|
498 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
|
499 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
500 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
|
501 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
|
502 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
503 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
|
504 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
|
505 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
506 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
|
507 if (blocking) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
508 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
509 //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
|
510 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
|
511 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
512 } 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
|
513 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
|
514 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
515 } 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
|
516 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
|
517 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
|
518 } 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
|
519 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
|
520 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
|
521 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
|
522 } 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
|
523 //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
|
524 if (!blocking) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
525 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
526 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
|
527 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
|
528 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
529 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
530 //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
|
531 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
|
532 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
533 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
534 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
535 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
|
536 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
537 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
|
538 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
|
539 blocking = 0; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
540 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
|
541 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
542 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
|
543 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
|
544 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
545 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
|
546 if (blocking) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
547 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
548 //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
|
549 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
|
550 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
551 } 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
|
552 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
|
553 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
|
554 } 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
|
555 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
|
556 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
|
557 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
|
558 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
559 //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
|
560 if (!blocking) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
561 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
562 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
|
563 blocking = 1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
564 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
565 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
566 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
567 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
568 } |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
569 #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
|
570 |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
571 const int mouse_delays[] = {112*7, 120*7, 96*7, 132*7, 104*7, 96*7, 112*7, 96*7}; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
572 |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
573 enum { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
574 KB_SETUP, |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
575 KB_READ, |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
576 KB_WRITE |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
577 }; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
578 |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
579 void io_control_write(io_port *port, uint8_t value, uint32_t current_cycle) |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
580 { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
581 uint8_t changes = value ^ port->control; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
582 if (changes) { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
583 for (int i = 0; i < 8; i++) |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
584 { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
585 if (!(value & 1 << i) && !(port->output & 1 << i)) { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
586 //port switched from output to input and the output value was 0 |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
587 //since there is a weak pull-up on input pins, this will lead |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
588 //to a slow rise from 0 to 1 if the pin isn't being externally driven |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
589 port->slow_rise_start[i] = current_cycle; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
590 } else { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
591 port->slow_rise_start[i] = CYCLE_NEVER; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
592 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
593 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
594 port->control = value; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
595 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
596 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
597 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
598 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
|
599 { |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
600 uint8_t old_output = (port->control & port->output) | (~port->control & 0xFF); |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
601 uint8_t output = (port->control & value) | (~port->control & 0xFF); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
602 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
|
603 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
604 case IO_GAMEPAD6: |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
605 //check if TH has changed |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
606 if ((old_output & TH) ^ (output & TH)) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
607 if (current_cycle >= port->device.pad.timeout_cycle) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
608 port->device.pad.th_counter = 0; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
609 } |
1144
be3df2d8530a
Increment TH counter on low to high transitions rather than high to low transitions for six button controllers. Fixes Charles MacDonald's SMS six button controller demo
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
610 if ((output & TH)) { |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
611 port->device.pad.th_counter++; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
612 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
613 port->device.pad.timeout_cycle = current_cycle + TH_TIMEOUT; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
614 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
615 break; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
616 case IO_MOUSE: |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
617 mouse_check_ready(port, current_cycle); |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
618 if (output & TH) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
619 //request is over or mouse is being reset |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
620 if (port->device.mouse.tr_counter) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
621 //request is over |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
622 port->device.mouse.last_read_x = port->device.mouse.latched_x; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
623 port->device.mouse.last_read_y = port->device.mouse.latched_y; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
624 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
625 port->device.mouse.tr_counter = 0; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
626 port->device.mouse.ready_cycle = CYCLE_NEVER; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
627 } else { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
628 if ((output & TR) != (old_output & TR)) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
629 int delay_index = port->device.mouse.tr_counter >= sizeof(mouse_delays) ? sizeof(mouse_delays)-1 : port->device.mouse.tr_counter; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
630 port->device.mouse.ready_cycle = current_cycle + mouse_delays[delay_index]; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
631 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
632 } |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
633 break; |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
634 case IO_SATURN_KEYBOARD: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
635 if (output & TH) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
636 //request is over |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
637 if (port->device.keyboard.tr_counter >= 10 && port->device.keyboard.read_pos != 0xFF) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
638 //remove scan code from buffer |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
639 port->device.keyboard.read_pos++; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
640 port->device.keyboard.read_pos &= 7; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
641 if (port->device.keyboard.read_pos == port->device.keyboard.write_pos) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
642 port->device.keyboard.read_pos = 0xFF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
643 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
644 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
645 port->device.keyboard.tr_counter = 0; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
646 } else { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
647 if ((output & TR) != (old_output & TR)) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
648 port->device.keyboard.tr_counter++; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
649 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
650 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
651 break; |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
652 case IO_XBAND_KEYBOARD: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
653 if (output & TH) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
654 //request is over |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
655 if ( |
1257
db28178bd2a1
Fix removal of scan codes from buffer in XBAND keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1256
diff
changeset
|
656 port->device.keyboard.mode == KB_READ && port->device.keyboard.tr_counter > 6 |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
657 && (port->device.keyboard.tr_counter & 1) |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
658 ) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
659 if (port->device.keyboard.events[port->device.keyboard.read_pos] & 0xFF00) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
660 port->device.keyboard.events[port->device.keyboard.read_pos] &= 0xFF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
661 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
662 port->device.keyboard.read_pos++; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
663 port->device.keyboard.read_pos &= 7; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
664 if (port->device.keyboard.read_pos == port->device.keyboard.write_pos) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
665 port->device.keyboard.read_pos = 0xFF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
666 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
667 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
668 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
669 port->device.keyboard.tr_counter = 0; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
670 port->device.keyboard.mode = KB_SETUP; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
671 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
672 if ((output & TR) != (old_output & TR)) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
673 port->device.keyboard.tr_counter++; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
674 if (port->device.keyboard.tr_counter == 2) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
675 port->device.keyboard.mode = (output & 0xF) ? KB_READ : KB_WRITE; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
676 } else if (port->device.keyboard.mode == KB_WRITE) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
677 switch (port->device.keyboard.tr_counter) |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
678 { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
679 case 3: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
680 //host writes 0b0001 |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
681 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
682 case 4: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
683 //host writes 0b0000 |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
684 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
685 case 5: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
686 //host writes 0b0000 |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
687 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
688 case 6: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
689 port->device.keyboard.cmd = output << 4; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
690 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
691 case 7: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
692 port->device.keyboard.cmd |= output & 0xF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
693 //TODO: actually do something with the command |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
694 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
695 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
696 } else if ( |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
697 port->device.keyboard.mode == KB_READ && port->device.keyboard.tr_counter > 7 |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
698 && !(port->device.keyboard.tr_counter & 1) |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
699 ) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
700 |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
701 if (port->device.keyboard.events[port->device.keyboard.read_pos] & 0xFF00) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
702 port->device.keyboard.events[port->device.keyboard.read_pos] &= 0xFF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
703 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
704 port->device.keyboard.read_pos++; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
705 port->device.keyboard.read_pos &= 7; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
706 if (port->device.keyboard.read_pos == port->device.keyboard.write_pos) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
707 port->device.keyboard.read_pos = 0xFF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
708 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
709 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
710 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
711 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
712 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
713 break; |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
714 #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
|
715 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
|
716 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
|
717 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
|
718 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
|
719 break; |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
720 #endif |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
721 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
722 port->output = value; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
723 |
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 |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
726 uint8_t get_scancode_bytes(io_port *port) |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
727 { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
728 if (port->device.keyboard.read_pos == 0xFF) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
729 return 0; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
730 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
731 uint8_t bytes = 0, read_pos = port->device.keyboard.read_pos; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
732 do { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
733 bytes += port->device.keyboard.events[read_pos] & 0xFF00 ? 2 : 1; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
734 read_pos++; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
735 read_pos &= 7; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
736 } while (read_pos != port->device.keyboard.write_pos); |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
737 |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
738 return bytes; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
739 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
740 |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
741 #define SLOW_RISE_DEVICE (30*7) |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
742 #define SLOW_RISE_INPUT (12*7) |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
743 |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
744 static uint8_t get_output_value(io_port *port, uint32_t current_cycle, uint32_t slow_rise_delay) |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
745 { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
746 uint8_t output = (port->control | 0x80) & port->output; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
747 for (int i = 0; i < 8; i++) |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
748 { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
749 if (!(port->control & 1 << i)) { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
750 if (port->slow_rise_start[i] != CYCLE_NEVER) { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
751 if (current_cycle - port->slow_rise_start[i] >= slow_rise_delay) { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
752 output |= 1 << i; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
753 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
754 } else { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
755 output |= 1 << i; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
756 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
757 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
758 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
759 return output; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
760 } |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
761 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
762 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
|
763 { |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
764 uint8_t output = get_output_value(port, current_cycle, SLOW_RISE_DEVICE); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
765 uint8_t control = port->control | 0x80; |
911
73732ae76fa8
IO port pins should read as high from the perspective of a device when they are set as inputs
Michael Pavone <pavone@retrodev.com>
parents:
910
diff
changeset
|
766 uint8_t th = output & 0x40; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
767 uint8_t input; |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
768 uint8_t device_driven; |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
769 if (current_cycle - last_poll_cycle > MIN_POLL_INTERVAL) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
770 process_events(); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
771 last_poll_cycle = current_cycle; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
772 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
773 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
|
774 { |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
775 case IO_GAMEPAD2: |
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
776 input = ~port->input[GAMEPAD_TH1]; |
1379
65f1d6558e9e
Update SMS code for changes supporting slow rise time emulation in IO code
Michael Pavone <pavone@retrodev.com>
parents:
1377
diff
changeset
|
777 device_driven = 0x3F; |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
778 break; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
779 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
|
780 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
781 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
|
782 if (!th) { |
bc127fa1f800
Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents:
886
diff
changeset
|
783 input |= 0xC; |
bc127fa1f800
Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents:
886
diff
changeset
|
784 } |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
785 //controller output is logically inverted |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
786 input = ~input; |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
787 device_driven = 0x3F; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
788 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
|
789 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
790 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
|
791 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
792 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
|
793 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
|
794 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
795 /*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
|
796 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
|
797 }*/ |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
798 if (th) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
799 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
|
800 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
|
801 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
802 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
|
803 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
804 } else { |
1144
be3df2d8530a
Increment TH counter on low to high transitions rather than high to low transitions for six button controllers. Fixes Charles MacDonald's SMS six button controller demo
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
805 if (port->device.pad.th_counter == 2) { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
806 input = port->input[GAMEPAD_TH0] | 0xF; |
1144
be3df2d8530a
Increment TH counter on low to high transitions rather than high to low transitions for six button controllers. Fixes Charles MacDonald's SMS six button controller demo
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
807 } else if(port->device.pad.th_counter == 3) { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
808 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
|
809 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
810 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
|
811 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
812 } |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
813 //controller output is logically inverted |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
814 input = ~input; |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
815 device_driven = 0x3F; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
816 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
817 } |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
818 case IO_MOUSE: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
819 { |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
820 mouse_check_ready(port, current_cycle); |
911
73732ae76fa8
IO port pins should read as high from the perspective of a device when they are set as inputs
Michael Pavone <pavone@retrodev.com>
parents:
910
diff
changeset
|
821 uint8_t tr = output & TR; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
822 if (th) { |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
823 if (tr) { |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
824 input = 0x10; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
825 } else { |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
826 input = 0; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
827 } |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
828 } else { |
913
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
912
diff
changeset
|
829 |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
830 int16_t delta_x = port->device.mouse.latched_x - port->device.mouse.last_read_x; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
831 int16_t delta_y = port->device.mouse.last_read_y - port->device.mouse.latched_y; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
832 switch (port->device.mouse.tr_counter) |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
833 { |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
834 case 0: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
835 input = 0xB; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
836 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
837 case 1: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
838 case 2: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
839 input = 0xF; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
840 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
841 case 3: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
842 input = 0; |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
843 if (delta_y > 255 || delta_y < -255) { |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
844 input |= 8; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
845 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
846 if (delta_x > 255 || delta_x < -255) { |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
847 input |= 4; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
848 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
849 if (delta_y < 0) { |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
850 input |= 2; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
851 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
852 if (delta_x < 0) { |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
853 input |= 1; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
854 } |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
855 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
856 case 4: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
857 input = port->input[0]; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
858 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
859 case 5: |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
860 input = delta_x >> 4 & 0xF; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
861 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
862 case 6: |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
863 input = delta_x & 0xF; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
864 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
865 case 7: |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
866 input = delta_y >> 4 & 0xF; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
867 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
868 case 8: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
869 default: |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
870 input = delta_y & 0xF; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
871 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
872 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
873 input |= ((port->device.mouse.tr_counter & 1) == 0) << 4; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
874 } |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
875 device_driven = 0x1F; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
876 break; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
877 } |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
878 case IO_SATURN_KEYBOARD: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
879 { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
880 if (th) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
881 input = 0x11; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
882 } else { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
883 uint8_t tr = output & TR; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
884 uint16_t code = port->device.keyboard.read_pos == 0xFF ? 0 |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
885 : port->device.keyboard.events[port->device.keyboard.read_pos]; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
886 switch (port->device.keyboard.tr_counter) |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
887 { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
888 case 0: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
889 input = 1; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
890 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
891 case 1: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
892 //Saturn peripheral ID |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
893 input = 3; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
894 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
895 case 2: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
896 //data size |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
897 input = 4; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
898 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
899 case 3: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
900 //d-pad |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
901 //TODO: set these based on keyboard state |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
902 input = 0xF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
903 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
904 case 4: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
905 //Start ABC |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
906 //TODO: set these based on keyboard state |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
907 input = 0xF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
908 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
909 case 5: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
910 //R XYZ |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
911 //TODO: set these based on keyboard state |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
912 input = 0xF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
913 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
914 case 6: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
915 //L and KBID |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
916 //TODO: set L based on keyboard state |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
917 input = 0x8; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
918 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
919 case 7: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
920 //Capslock, Numlock, Scrolllock |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
921 //TODO: set these based on keyboard state |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
922 input = 0; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
923 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
924 case 8: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
925 input = 6; |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
926 if (code & 0xFF00) { |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
927 //break |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
928 input |= 1; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
929 } else if (code) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
930 input |= 8; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
931 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
932 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
933 case 9: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
934 input = code >> 4 & 0xF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
935 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
936 case 10: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
937 input = code & 0xF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
938 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
939 case 11: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
940 input = 0; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
941 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
942 default: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
943 input = 1; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
944 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
945 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
946 input |= ((port->device.keyboard.tr_counter & 1) == 0) << 4; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
947 } |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
948 device_driven = 0x1F; |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
949 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
950 } |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
951 case IO_XBAND_KEYBOARD: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
952 { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
953 if (th) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
954 input = 0x1C; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
955 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
956 uint8_t size; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
957 if (port->device.keyboard.mode == KB_SETUP || port->device.keyboard.mode == KB_READ) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
958 switch (port->device.keyboard.tr_counter) |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
959 { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
960 case 0: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
961 input = 0x3; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
962 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
963 case 1: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
964 input = 0x6; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
965 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
966 case 2: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
967 //This is where thoe host indicates a read or write |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
968 //presumably, the keyboard only outputs this if the host |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
969 //is not already driving the data bus low |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
970 input = 0x9; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
971 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
972 case 3: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
973 size = get_scancode_bytes(port); |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
974 if (size) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
975 ++size; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
976 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
977 if (size > 15) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
978 size = 15; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
979 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
980 input = size; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
981 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
982 case 4: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
983 case 5: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
984 //always send packet type 0 for now |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
985 input = 0; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
986 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
987 default: |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
988 if (port->device.keyboard.read_pos == 0xFF) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
989 //we've run out of bytes |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
990 input = 0; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
991 } else if (port->device.keyboard.events[port->device.keyboard.read_pos] & 0xFF00) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
992 if (port->device.keyboard.tr_counter & 1) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
993 input = port->device.keyboard.events[port->device.keyboard.read_pos] >> 8 & 0xF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
994 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
995 input = port->device.keyboard.events[port->device.keyboard.read_pos] >> 12; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
996 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
997 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
998 if (port->device.keyboard.tr_counter & 1) { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
999 input = port->device.keyboard.events[port->device.keyboard.read_pos] & 0xF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1000 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1001 input = port->device.keyboard.events[port->device.keyboard.read_pos] >> 4; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1002 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1003 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1004 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1005 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1006 } else { |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1007 input = 0xF; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1008 } |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1009 input |= ((port->device.keyboard.tr_counter & 1) == 0) << 4; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1010 } |
1453
cd6e566eb6b9
Fix regression in XBAND keyboard support. Fixes ticket:33
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1011 //this is not strictly correct at all times, but good enough for now |
cd6e566eb6b9
Fix regression in XBAND keyboard support. Fixes ticket:33
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1012 device_driven = 0x1F; |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1013 break; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1014 } |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
1015 #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
|
1016 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
|
1017 if (!th) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1018 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1019 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
|
1020 } |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1021 input = port->input[th ? IO_TH1 : IO_TH0]; |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1022 device_driven = 0x3F; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1023 break; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1024 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
|
1025 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
|
1026 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1027 //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
|
1028 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
|
1029 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1030 service_socket(port); |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1031 input = port->input[IO_TH0]; |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1032 device_driven = 0x7F; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1033 break; |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
1034 #endif |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1035 default: |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1036 input = 0; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1037 device_driven = 0; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1038 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
|
1039 } |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1040 uint8_t value = (input & (~control) & device_driven) | (port->output & control); |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1041 //deal with pins that are configured as inputs, but not being actively driven by the device |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1042 uint8_t floating = (~device_driven) & (~control); |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1043 if (floating) { |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1044 value |= get_output_value(port, current_cycle, SLOW_RISE_INPUT) & floating; |
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1045 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1046 /*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
|
1047 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
|
1048 }*/ |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1049 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
|
1050 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1051 |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1052 void io_serialize(io_port *port, serialize_buffer *buf) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1053 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1054 save_int8(buf, port->output); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1055 save_int8(buf, port->control); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1056 save_int8(buf, port->serial_out); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1057 save_int8(buf, port->serial_in); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1058 save_int8(buf, port->serial_ctrl); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1059 save_int8(buf, port->device_type); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1060 save_buffer32(buf, port->slow_rise_start, 8); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1061 switch (port->device_type) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1062 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1063 case IO_GAMEPAD6: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1064 save_int32(buf, port->device.pad.timeout_cycle); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1065 save_int16(buf, port->device.pad.th_counter); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1066 break; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1067 case IO_MOUSE: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1068 save_int32(buf, port->device.mouse.ready_cycle); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1069 save_int16(buf, port->device.mouse.last_read_x); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1070 save_int16(buf, port->device.mouse.last_read_y); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1071 save_int16(buf, port->device.mouse.latched_x); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1072 save_int16(buf, port->device.mouse.latched_y); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1073 save_int8(buf, port->device.mouse.tr_counter); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1074 break; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1075 case IO_SATURN_KEYBOARD: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1076 case IO_XBAND_KEYBOARD: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1077 save_int8(buf, port->device.keyboard.tr_counter); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1078 if (port->device_type == IO_XBAND_KEYBOARD) { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1079 save_int8(buf, port->device.keyboard.mode); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1080 save_int8(buf, port->device.keyboard.cmd); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1081 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1082 break; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1083 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1084 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1085 |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1086 void io_deserialize(deserialize_buffer *buf, void *vport) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1087 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1088 io_port *port = vport; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1089 port->output = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1090 port->control = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1091 port->serial_out = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1092 port->serial_in = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1093 port->serial_ctrl = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1094 uint8_t device_type = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1095 if (device_type != port->device_type) { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1096 warning("Loaded save state has a different device type from the current configuration"); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1097 return; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1098 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1099 switch (port->device_type) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1100 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1101 case IO_GAMEPAD6: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1102 port->device.pad.timeout_cycle = load_int32(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1103 port->device.pad.th_counter = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1104 break; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1105 case IO_MOUSE: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1106 port->device.mouse.ready_cycle = load_int32(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1107 port->device.mouse.last_read_x = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1108 port->device.mouse.last_read_y = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1109 port->device.mouse.latched_x = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1110 port->device.mouse.latched_y = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1111 port->device.mouse.tr_counter = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1112 break; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1113 case IO_SATURN_KEYBOARD: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1114 case IO_XBAND_KEYBOARD: |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1115 port->device.keyboard.tr_counter = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1116 if (port->device_type == IO_XBAND_KEYBOARD) { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1117 port->device.keyboard.mode = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1118 port->device.keyboard.cmd = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1119 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1120 break; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1121 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1400
diff
changeset
|
1122 } |