1 #ifndef _controllerframe__hpp__included__
2 #define _controllerframe__hpp__included__
18 #include "library/portctrl-data.hpp"
19 #include "library/threads.hpp"
24 class emulator_dispatch
;
30 class controller_state
36 controller_state(project_state
& _project
, movie_logic
& _mlogic
, button_mapping
& _buttons
,
37 emulator_dispatch
& _dispatch
, status_updater
& _supdater
) throw();
39 * Convert lcid (Logical Controller ID) into pcid (Physical Controler ID).
41 * Parameter lcid: The logical controller ID.
42 * Return: The physical controller ID, or <-1, -1> if no such controller exists.
44 std::pair
<int, int> lcid_to_pcid(unsigned lcid
) throw();
46 * Lookup (port,controller) pair corresponding to given legacy pcid.
48 * Parameter pcid: The legacy pcid.
49 * Returns: The controller index, or <-1, -1> if no such thing exists.
50 * Note: Even if this does return a valid index, it still may not exist.
52 std::pair
<int, int> legacy_pcid_to_pair(unsigned pcid
) throw();
54 * Is given pcid present?
56 * Parameter port: The port.
57 * Parameter controller: The controller.
58 * Returns: True if present, false if not.
60 bool pcid_present(unsigned port
, unsigned controller
) throw();
64 * Parameter ptype: The new types for ports.
65 * Throws std::runtime_error: Illegal port type.
67 void set_ports(const portctrl::type_set
& ptype
) throw(std::runtime_error
);
69 * Get status of current controls (with autohold/autofire factored in).
71 * Parameter framenum: Number of current frame (for evaluating autofire).
72 * Returns: The current controls.
74 portctrl::frame
get(uint64_t framenum
) throw();
76 * Commit given controls (autohold/autofire is ignored).
78 * Parameter controls: The controls to commit
80 void commit(portctrl::frame controls
) throw();
82 * Get status of committed controls.
83 * Returns: The committed controls.
85 portctrl::frame
get_committed() throw();
89 portctrl::frame
get_blank() throw();
91 * Send analog input to given controller.
93 * Parameter port: The port to send input to.
94 * Parameter controller: The controller to send input to.
95 * Parameter control: The control to send.
96 * Parameter x: The coordinate to send.
98 void analog(unsigned port
, unsigned controller
, unsigned control
, short x
) throw();
100 * Manipulate autohold.
102 * Parameter port: The port.
103 * Parameter controller: The controller.
104 * Parameter pbid: The physical button ID to manipulate.
105 * Parameter newstate: The new state for autohold.
107 void autohold2(unsigned port
, unsigned controller
, unsigned pbid
, bool newstate
) throw();
111 * Parameter port: The port.
112 * Parameter controller: The controller.
113 * Parameter pbid: The physical button ID to query.
114 * Returns: The state of autohold.
116 bool autohold2(unsigned port
, unsigned controller
, unsigned pbid
) throw();
118 * Reset all frame holds.
120 void reset_framehold() throw();
122 * Manipulate hold for frame.
124 * Parameter port: The port.
125 * Parameter controller: The controller.
126 * Parameter pbid: The physical button ID to manipulate.
127 * Parameter newstate: The new state for framehold.
129 void framehold2(unsigned port
, unsigned controller
, unsigned pbid
, bool newstate
) throw();
131 * Query hold for frame.
133 * Parameter port: The port.
134 * Parameter controller: The controller.
135 * Parameter pbid: The physical button ID to query.
136 * Returns: The state of framehold.
138 bool framehold2(unsigned port
, unsigned controller
, unsigned pbid
) throw();
142 * Parameter port: The port.
143 * Parameter controller: The controller.
144 * Parameter pbid: The physical button ID to manipulate.
145 * Parameter newstate: The new state for button.
147 void button2(unsigned port
, unsigned controller
, unsigned pbid
, bool newstate
) throw();
151 * Parameter port: The port.
152 * Parameter controller: The controller.
153 * Parameter pbid: The physical button ID to query.
154 * Returns: The state of button.
156 bool button2(unsigned port
, unsigned controller
, unsigned pbid
) throw();
158 * Manipulate autofire.
160 * Parameter port: The port.
161 * Parameter controller: The controller.
162 * Parameter pbid: The physical button ID to manipulate.
163 * Parameter duty: The new duty cycle for autofire.
164 * Parameter cyclelen: The new cycle length.
166 void autofire2(unsigned port
, unsigned controller
, unsigned pbid
, unsigned duty
, unsigned cyclelen
) throw();
170 * Parameter port: The port.
171 * Parameter controller: The controller.
172 * Parameter pbid: The physical button ID to query.
173 * Returns: The state of autofire.
175 std::pair
<unsigned, unsigned> autofire2(unsigned port
, unsigned controller
, unsigned pbid
) throw();
177 * Manipulate TASinput.
179 * Parameter port: The port.
180 * Parameter controller: The controller.
181 * Parameter pbid: The physical button ID to manipulate.
182 * Parameter state: The new state.
184 void tasinput(unsigned port
, unsigned controller
, unsigned pbid
, int16_t state
) throw();
188 * Parameter port: The port.
189 * Parameter controller: The controller.
190 * Parameter pbid: The physical button ID to query.
191 * Returns: The state of tasinput.
193 int16_t tasinput(unsigned port
, unsigned controller
, unsigned pbid
) throw();
195 * Enage/Disenage tasinput.
197 void tasinput_enable(bool enabled
);
201 bool is_present(unsigned port
, unsigned controller
) throw();
202 void erase_macro(const std::string
& macro
);
203 std::set
<std::string
> enumerate_macro();
204 portctrl::macro
& get_macro(const std::string
& macro
);
205 void set_macro(const std::string
& macro
, const portctrl::macro
& m
);
206 void apply_macro(portctrl::frame
& f
);
207 void rename_macro(const std::string
& old
, const std::string
& newn
);
208 void do_macro(const std::string
& a
, int mode
);
209 std::set
<std::string
> active_macro_set();
210 void advance_macros();
211 std::map
<std::string
, uint64_t> get_macro_frames();
212 void set_macro_frames(const std::map
<std::string
, uint64_t>& f
);
216 uint64_t first_frame
;
219 bool eval_at(uint64_t frame
);
226 void reread_tasinput_mode(const portctrl::type_set
& ptype
);
227 const portctrl::type_set
* types
;
228 portctrl::frame _input
;
229 portctrl::frame _autohold
;
230 portctrl::frame _framehold
;
231 std::map
<unsigned, autofire_info
> _autofire
;
232 std::map
<unsigned, tasinput_info
> _tasinput
;
233 bool tasinput_enaged
;
234 portctrl::frame _committed
;
235 std::map
<std::string
, portctrl::macro
> all_macros
;
236 std::list
<std::pair
<uint64_t, portctrl::macro
*>> active_macros
;
237 threads::lock macro_lock
;
238 project_state
& project
;
240 button_mapping
& buttons
;
241 emulator_dispatch
& edispatch
;
242 status_updater
& supdater
;