Mercurial > repos > blastem
annotate io.h @ 1402:458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 15 Jun 2017 19:24:16 -0700 |
parents | 040c5600e2d9 |
children | 4e5797b3935a |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
2 Copyright 2013 Michael Pavone |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael 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:
421
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:
421
diff
changeset
|
5 */ |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #ifndef 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
|
7 #define 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
|
8 #include <stdint.h> |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
9 #include "tern.h" |
913
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
912
diff
changeset
|
10 #include "romdb.h" |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
11 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
12 enum { |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
13 IO_GAMEPAD2, |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
14 IO_GAMEPAD3, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
15 IO_GAMEPAD6, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
16 IO_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:
971
diff
changeset
|
17 IO_SATURN_KEYBOARD, |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1215
diff
changeset
|
18 IO_XBAND_KEYBOARD, |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
19 IO_MENACER, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
20 IO_JUSTIFIER, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
21 IO_SEGA_MULTI, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
22 IO_EA_MULTI_A, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
23 IO_EA_MULTI_B, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
24 IO_SEGA_PARALLEL, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
25 IO_GENERIC, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
26 IO_NONE |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
27 }; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 typedef struct { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
30 union { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
31 struct { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
32 uint32_t timeout_cycle; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
33 uint16_t th_counter; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
34 uint16_t gamepad_num; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
35 } pad; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
36 struct { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
37 int data_fd; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
38 int listen_fd; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
39 } stream; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
40 struct { |
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:
907
diff
changeset
|
41 uint32_t ready_cycle; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
42 uint16_t last_read_x; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
43 uint16_t last_read_y; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
44 uint16_t cur_x; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
45 uint16_t cur_y; |
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:
907
diff
changeset
|
46 uint16_t 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:
907
diff
changeset
|
47 uint16_t latched_y; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
48 uint8_t tr_counter; |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
49 uint8_t mouse_num; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
50 } 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:
971
diff
changeset
|
51 struct { |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
971
diff
changeset
|
52 uint16_t events[8]; |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
971
diff
changeset
|
53 uint8_t read_pos; |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
971
diff
changeset
|
54 uint8_t write_pos; |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
55 uint8_t tr_counter; |
1232
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1215
diff
changeset
|
56 uint8_t mode; |
c0120977eeea
Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents:
1215
diff
changeset
|
57 uint8_t cmd; |
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:
971
diff
changeset
|
58 } keyboard; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
59 } device; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
60 uint8_t output; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
61 uint8_t control; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
62 uint8_t input[3]; |
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:
1254
diff
changeset
|
63 uint32_t slow_rise_start[8]; |
1215
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1207
diff
changeset
|
64 uint8_t serial_out; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1207
diff
changeset
|
65 uint8_t serial_in; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1207
diff
changeset
|
66 uint8_t serial_ctrl; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
67 uint8_t device_type; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 } io_port; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
70 typedef struct { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
71 io_port ports[3]; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
72 uint8_t mouse_mode; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
73 uint8_t mouse_captured; |
1254
d966298442d4
Implement keyboard capture functionality
Michael Pavone <pavone@retrodev.com>
parents:
1232
diff
changeset
|
74 uint8_t keyboard_captured; |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
75 } sega_io; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
76 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 #define GAMEPAD_TH0 0 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 #define GAMEPAD_TH1 1 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 #define GAMEPAD_EXTRA 2 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 #define GAMEPAD_NONE 0xF |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
82 #define IO_TH0 0 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
83 #define IO_TH1 1 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
84 #define IO_STATE 2 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
85 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
86 enum { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
87 IO_WRITE_PENDING, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
88 IO_WRITTEN, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
89 IO_READ_PENDING, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
90 IO_READ |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
91 }; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
92 |
971
e28f365605da
Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
93 typedef struct genesis_context genesis_context; |
e28f365605da
Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
94 |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
95 void set_keybindings(sega_io *io); |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
96 void map_all_bindings(sega_io *io); |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
97 void setup_io_devices(tern_node * config, rom_info *rom, 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
|
98 void io_adjust_cycles(io_port * pad, uint32_t current_cycle, uint32_t deduction); |
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:
1254
diff
changeset
|
99 void io_control_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
|
100 void io_data_write(io_port * pad, uint8_t value, uint32_t 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
|
101 uint8_t io_data_read(io_port * pad, uint32_t current_cycle); |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
102 void handle_keydown(int keycode, uint8_t scancode); |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
103 void handle_keyup(int keycode, uint8_t scancode); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 void handle_joydown(int joystick, int button); |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 void handle_joyup(int joystick, int button); |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 void handle_joy_dpad(int joystick, int dpad, uint8_t state); |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1194
diff
changeset
|
107 void handle_joy_axis(int joystick, int axis, int16_t value); |
1194
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
108 void handle_joy_added(int joystick); |
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:
913
diff
changeset
|
109 void handle_mouse_moved(int mouse, uint16_t x, uint16_t y, int16_t deltax, int16_t deltay); |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
110 void handle_mousedown(int mouse, int button); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
111 void handle_mouseup(int mouse, int 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
|
112 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 #endif //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
|
114 |