Lua: Fix type confusion between signed and unsigned
[lsnes.git] / include / core / controllerframe.hpp
blob9ba11f9deb8380a15acd83230efc6bb4d1025c1b
1 #ifndef _controllerframe__hpp__included__
2 #define _controllerframe__hpp__included__
4 #include <cstring>
5 #include <climits>
6 #include <cstdio>
7 #include <cstdlib>
8 #include <cstdio>
9 #include <cstdint>
10 #include <sstream>
11 #include <iomanip>
12 #include <iostream>
13 #include <stdexcept>
14 #include <string>
15 #include <vector>
16 #include <map>
17 #include <list>
18 #include "library/portctrl-data.hpp"
19 #include "library/command.hpp"
20 #include "library/threads.hpp"
22 class project_state;
23 class movie_logic;
24 class button_mapping;
25 class emulator_dispatch;
26 class status_updater;
28 /**
29 * Controllers state.
31 class controller_state
33 public:
34 /**
35 * Constructor.
37 controller_state(project_state& _project, movie_logic& _mlogic, button_mapping& _buttons,
38 emulator_dispatch& _dispatch, status_updater& _supdater, command::group& _cmd) throw();
39 /**
40 * Convert lcid (Logical Controller ID) into pcid (Physical Controler ID).
42 * Parameter lcid: The logical controller ID.
43 * Return: The physical controller ID, or <-1, -1> if no such controller exists.
45 std::pair<int, int> lcid_to_pcid(unsigned lcid) throw();
46 /**
47 * Lookup (port,controller) pair corresponding to given legacy pcid.
49 * Parameter pcid: The legacy pcid.
50 * Returns: The controller index, or <-1, -1> if no such thing exists.
51 * Note: Even if this does return a valid index, it still may not exist.
53 std::pair<int, int> legacy_pcid_to_pair(unsigned pcid) throw();
54 /**
55 * Is given pcid present?
57 * Parameter port: The port.
58 * Parameter controller: The controller.
59 * Returns: True if present, false if not.
61 bool pcid_present(unsigned port, unsigned controller) throw();
62 /**
63 * Set types of ports.
65 * Parameter ptype: The new types for ports.
66 * Throws std::runtime_error: Illegal port type.
68 void set_ports(const portctrl::type_set& ptype) throw(std::runtime_error);
69 /**
70 * Get status of current controls (with autohold/autofire factored in).
72 * Parameter framenum: Number of current frame (for evaluating autofire).
73 * Returns: The current controls.
75 portctrl::frame get(uint64_t framenum) throw();
76 /**
77 * Commit given controls (autohold/autofire is ignored).
79 * Parameter controls: The controls to commit
81 void commit(portctrl::frame controls) throw();
82 /**
83 * Get status of committed controls.
84 * Returns: The committed controls.
86 portctrl::frame get_committed() throw();
87 /**
88 * Get blank frame.
90 portctrl::frame get_blank() throw();
91 /**
92 * Send analog input to given controller.
94 * Parameter port: The port to send input to.
95 * Parameter controller: The controller to send input to.
96 * Parameter control: The control to send.
97 * Parameter x: The coordinate to send.
99 void analog(unsigned port, unsigned controller, unsigned control, short x) throw();
101 * Manipulate autohold.
103 * Parameter port: The port.
104 * Parameter controller: The controller.
105 * Parameter pbid: The physical button ID to manipulate.
106 * Parameter newstate: The new state for autohold.
108 void autohold2(unsigned port, unsigned controller, unsigned pbid, bool newstate) throw();
110 * Query autohold.
112 * Parameter port: The port.
113 * Parameter controller: The controller.
114 * Parameter pbid: The physical button ID to query.
115 * Returns: The state of autohold.
117 bool autohold2(unsigned port, unsigned controller, unsigned pbid) throw();
119 * Reset all frame holds.
121 void reset_framehold() throw();
123 * Manipulate hold for frame.
125 * Parameter port: The port.
126 * Parameter controller: The controller.
127 * Parameter pbid: The physical button ID to manipulate.
128 * Parameter newstate: The new state for framehold.
130 void framehold2(unsigned port, unsigned controller, unsigned pbid, bool newstate) throw();
132 * Query hold for frame.
134 * Parameter port: The port.
135 * Parameter controller: The controller.
136 * Parameter pbid: The physical button ID to query.
137 * Returns: The state of framehold.
139 bool framehold2(unsigned port, unsigned controller, unsigned pbid) throw();
141 * Manipulate button.
143 * Parameter port: The port.
144 * Parameter controller: The controller.
145 * Parameter pbid: The physical button ID to manipulate.
146 * Parameter newstate: The new state for button.
148 void button2(unsigned port, unsigned controller, unsigned pbid, bool newstate) throw();
150 * Query button.
152 * Parameter port: The port.
153 * Parameter controller: The controller.
154 * Parameter pbid: The physical button ID to query.
155 * Returns: The state of button.
157 bool button2(unsigned port, unsigned controller, unsigned pbid) throw();
159 * Manipulate autofire.
161 * Parameter port: The port.
162 * Parameter controller: The controller.
163 * Parameter pbid: The physical button ID to manipulate.
164 * Parameter duty: The new duty cycle for autofire.
165 * Parameter cyclelen: The new cycle length.
167 void autofire2(unsigned port, unsigned controller, unsigned pbid, unsigned duty, unsigned cyclelen) throw();
169 * Query autofire.
171 * Parameter port: The port.
172 * Parameter controller: The controller.
173 * Parameter pbid: The physical button ID to query.
174 * Returns: The state of autofire.
176 std::pair<unsigned, unsigned> autofire2(unsigned port, unsigned controller, unsigned pbid) throw();
178 * Manipulate TASinput.
180 * Parameter port: The port.
181 * Parameter controller: The controller.
182 * Parameter pbid: The physical button ID to manipulate.
183 * Parameter state: The new state.
185 void tasinput(unsigned port, unsigned controller, unsigned pbid, int16_t state) throw();
187 * Query tasinput.
189 * Parameter port: The port.
190 * Parameter controller: The controller.
191 * Parameter pbid: The physical button ID to query.
192 * Returns: The state of tasinput.
194 int16_t tasinput(unsigned port, unsigned controller, unsigned pbid) throw();
196 * Enage/Disenage tasinput.
198 void tasinput_enable(bool enabled);
200 * TODO: Document.
202 bool is_present(unsigned port, unsigned controller) throw();
203 void erase_macro(const std::string& macro);
204 std::set<std::string> enumerate_macro();
205 portctrl::macro& get_macro(const std::string& macro);
206 void set_macro(const std::string& macro, const portctrl::macro& m);
207 void apply_macro(portctrl::frame& f);
208 void rename_macro(const std::string& old, const std::string& newn);
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);
213 private:
214 void do_macro(const std::string& a, int mode);
215 struct autofire_info
217 uint64_t first_frame;
218 unsigned duty;
219 unsigned cyclelen;
220 bool eval_at(uint64_t frame);
222 struct tasinput_info
224 int mode;
225 int16_t state;
227 void reread_tasinput_mode(const portctrl::type_set& ptype);
228 const portctrl::type_set* types;
229 portctrl::frame _input;
230 portctrl::frame _autohold;
231 portctrl::frame _framehold;
232 std::map<unsigned, autofire_info> _autofire;
233 std::map<unsigned, tasinput_info> _tasinput;
234 bool tasinput_enaged;
235 portctrl::frame _committed;
236 std::map<std::string, portctrl::macro> all_macros;
237 std::list<std::pair<uint64_t, portctrl::macro*>> active_macros;
238 threads::lock macro_lock;
239 project_state& project;
240 movie_logic& mlogic;
241 button_mapping& buttons;
242 emulator_dispatch& edispatch;
243 status_updater& supdater;
244 command::group& cmd;
245 command::_fnptr<const std::string&> macro_p;
246 command::_fnptr<const std::string&> macro_r;
247 command::_fnptr<const std::string&> macro_t;
250 #endif