1//============================================================================
2//
3// SSSS tt lll lll
4// SS SS tt ll ll
5// SS tttttt eeee ll ll aaaa
6// SSSS tt ee ee ll ll aa
7// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
8// SS SS tt ee ll ll aa aa
9// SSSS ttt eeeee llll llll aaaaa
10//
11// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony
12// and the Stella Team
13//
14// See the file "License.txt" for information on usage and redistribution of
15// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16//============================================================================
17
18#ifndef EVENT_HXX
19#define EVENT_HXX
20
21#include <mutex>
22#include <set>
23
24#include "bspf.hxx"
25#include "StellaKeys.hxx"
26
27/**
28 @author Stephen Anthony, Christian Speckner, Thomas Jentzsch
29*/
30class Event
31{
32 public:
33 /**
34 Enumeration of all possible events in Stella, including both
35 console and controller event types as well as events that aren't
36 technically part of the emulation core.
37 */
38 enum Type
39 {
40 NoType = 0,
41 ConsoleColor, ConsoleBlackWhite,
42 ConsoleLeftDiffA, ConsoleLeftDiffB,
43 ConsoleRightDiffA, ConsoleRightDiffB,
44 ConsoleSelect, ConsoleReset,
45 ConsoleLeftDiffToggle, ConsoleRightDiffToggle, ConsoleColorToggle,
46 Console7800Pause,
47
48 JoystickZeroUp, JoystickZeroDown, JoystickZeroLeft, JoystickZeroRight,
49 JoystickZeroFire, JoystickZeroFire5, JoystickZeroFire9,
50 JoystickOneUp, JoystickOneDown, JoystickOneLeft, JoystickOneRight,
51 JoystickOneFire, JoystickOneFire5, JoystickOneFire9,
52
53 PaddleZeroDecrease, PaddleZeroIncrease, PaddleZeroAnalog, PaddleZeroFire,
54 PaddleOneDecrease, PaddleOneIncrease, PaddleOneAnalog, PaddleOneFire,
55 PaddleTwoDecrease, PaddleTwoIncrease, PaddleTwoAnalog, PaddleTwoFire,
56 PaddleThreeDecrease, PaddleThreeIncrease, PaddleThreeAnalog, PaddleThreeFire,
57
58 KeyboardZero1, KeyboardZero2, KeyboardZero3,
59 KeyboardZero4, KeyboardZero5, KeyboardZero6,
60 KeyboardZero7, KeyboardZero8, KeyboardZero9,
61 KeyboardZeroStar, KeyboardZero0, KeyboardZeroPound,
62
63 KeyboardOne1, KeyboardOne2, KeyboardOne3,
64 KeyboardOne4, KeyboardOne5, KeyboardOne6,
65 KeyboardOne7, KeyboardOne8, KeyboardOne9,
66 KeyboardOneStar, KeyboardOne0, KeyboardOnePound,
67
68 Combo1, Combo2, Combo3, Combo4, Combo5, Combo6, Combo7, Combo8,
69 Combo9, Combo10, Combo11, Combo12, Combo13, Combo14, Combo15, Combo16,
70
71 MouseAxisXValue, MouseAxisYValue,
72 MouseButtonLeftValue, MouseButtonRightValue,
73
74 ChangeState, LoadState, SaveState, TakeSnapshot, Quit,
75 TogglePauseMode, OptionsMenuMode, CmdMenuMode, TimeMachineMode, DebuggerMode, ExitMode,
76 Fry, VolumeDecrease, VolumeIncrease, SoundToggle, VidmodeDecrease, VidmodeIncrease,
77 RewindPause, UnwindPause,
78
79 UIUp, UIDown, UILeft, UIRight, UIHome, UIEnd, UIPgUp, UIPgDown,
80 UISelect, UINavPrev, UINavNext, UIOK, UICancel, UIPrevDir,
81 UITabPrev, UITabNext,
82
83 ToggleFullScreen,
84 VidmodeStd, VidmodeRGB, VidmodeSVideo, VidModeComposite, VidModeBad, VidModeCustom,
85 PreviousAttribute, NextAttribute, DecreaseAttribute, IncreaseAttribute,
86 ScanlinesDecrease, ScanlinesIncrease,
87
88 ToggleP0Collision, ToggleP0Bit, ToggleP1Collision, ToggleP1Bit,
89 ToggleM0Collision, ToggleM0Bit, ToggleM1Collision, ToggleM1Bit,
90 ToggleBLCollision, ToggleBLBit, TogglePFCollision, TogglePFBit,
91 ToggleCollisions, ToggleBits, ToggleFixedColors,
92
93 DecreasePhosphor, IncreasePhosphor, TogglePhosphor, ToggleJitter,
94 ToggleFrameStats, ToggleTimeMachine,
95 ToggleContSnapshots, ToggleContSnapshotsFrame,
96 ToggleColorLoss, TogglePalette,
97
98 HandleMouseControl, ToggleGrabMouse, ToggleSAPortOrder,
99 DecreaseFormat, IncreaseFormat, ReloadConsole,
100
101 Rewind1Menu, Rewind10Menu, RewindAllMenu,
102 Unwind1Menu, Unwind10Menu, UnwindAllMenu,
103
104 StartPauseMode, SaveAllStates, LoadAllStates,
105 DecreaseOverscan, IncreaseOverScan,
106
107 ToggleAutoSlot,
108
109 CompuMateFunc, CompuMateShift,
110 CompuMate0, CompuMate1, CompuMate2, CompuMate3, CompuMate4,
111 CompuMate5, CompuMate6, CompuMate7, CompuMate8, CompuMate9,
112 CompuMateA, CompuMateB, CompuMateC, CompuMateD, CompuMateE,
113 CompuMateF, CompuMateG, CompuMateH, CompuMateI, CompuMateJ,
114 CompuMateK, CompuMateL, CompuMateM, CompuMateN, CompuMateO,
115 CompuMateP, CompuMateQ, CompuMateR, CompuMateS, CompuMateT,
116 CompuMateU, CompuMateV, CompuMateW, CompuMateX, CompuMateY,
117 CompuMateZ,
118 CompuMateComma, CompuMatePeriod, CompuMateEnter, CompuMateSpace,
119 CompuMateQuestion, CompuMateLeftBracket, CompuMateRightBracket, CompuMateMinus,
120 CompuMateQuote, CompuMateBackspace, CompuMateEquals, CompuMatePlus,
121 CompuMateSlash,
122
123 LastType
124
125 };
126
127 // Event categorizing groups
128 enum Group
129 {
130 Menu, Emulation,
131 Misc, AudioVideo, States, Console, Joystick, Paddles, Keyboard,
132 Debug, Combo,
133 LastGroup
134 };
135
136 // Event list version, update if the id of existing event types changed
137 static constexpr Int32 VERSION = 1;
138
139 using EventSet = std::set<Event::Type>;
140
141 public:
142 /**
143 Create a new event object.
144 */
145 Event() { clear(); }
146
147 public:
148 /**
149 Get the value associated with the event of the specified type.
150 */
151 Int32 get(Type type) const {
152 std::lock_guard<std::mutex> lock(myMutex);
153
154 return myValues[type];
155 }
156
157 /**
158 Set the value associated with the event of the specified type.
159 */
160 void set(Type type, Int32 value) {
161 std::lock_guard<std::mutex> lock(myMutex);
162
163 myValues[type] = value;
164 }
165
166 /**
167 Clears the event array (resets to initial state).
168 */
169 void clear()
170 {
171 std::lock_guard<std::mutex> lock(myMutex);
172
173 for(Int32 i = 0; i < LastType; ++i)
174 myValues[i] = Event::NoType;
175 }
176
177 /**
178 Tests if a given event represents continuous or analog values.
179 */
180 static bool isAnalog(Type type)
181 {
182 switch(type)
183 {
184 case Event::PaddleZeroAnalog:
185 case Event::PaddleOneAnalog:
186 case Event::PaddleTwoAnalog:
187 case Event::PaddleThreeAnalog:
188 return true;
189 default:
190 return false;
191 }
192 }
193
194 private:
195 // Array of values associated with each event type
196 Int32 myValues[LastType];
197
198 mutable std::mutex myMutex;
199
200 private:
201 // Following constructors and assignment operators not supported
202 Event(const Event&) = delete;
203 Event(Event&&) = delete;
204 Event& operator=(const Event&) = delete;
205 Event& operator=(Event&&) = delete;
206};
207
208// Hold controller related events
209// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
210static const Event::EventSet LeftJoystickEvents = {
211 Event::JoystickZeroUp, Event::JoystickZeroDown, Event::JoystickZeroLeft, Event::JoystickZeroRight,
212 Event::JoystickZeroFire, Event::JoystickZeroFire5, Event::JoystickZeroFire9,
213};
214// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
215static const Event::EventSet RightJoystickEvents = {
216 Event::JoystickOneUp, Event::JoystickOneDown, Event::JoystickOneLeft, Event::JoystickOneRight,
217 Event::JoystickOneFire, Event::JoystickOneFire5, Event::JoystickOneFire9
218};
219
220// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
221static const Event::EventSet LeftPaddlesEvents = {
222 Event::PaddleZeroDecrease, Event::PaddleZeroIncrease, Event::PaddleZeroAnalog, Event::PaddleZeroFire,
223 Event::PaddleOneDecrease, Event::PaddleOneIncrease, Event::PaddleOneAnalog, Event::PaddleOneFire,
224};
225
226// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
227static const Event::EventSet RightPaddlesEvents = {
228 Event::PaddleTwoDecrease, Event::PaddleTwoIncrease, Event::PaddleTwoAnalog, Event::PaddleTwoFire,
229 Event::PaddleThreeDecrease, Event::PaddleThreeIncrease, Event::PaddleThreeAnalog, Event::PaddleThreeFire,
230};
231
232// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
233static const Event::EventSet LeftKeypadEvents = {
234 Event::KeyboardZero1, Event::KeyboardZero2, Event::KeyboardZero3,
235 Event::KeyboardZero4, Event::KeyboardZero5, Event::KeyboardZero6,
236 Event::KeyboardZero7, Event::KeyboardZero8, Event::KeyboardZero9,
237 Event::KeyboardZeroStar, Event::KeyboardZero0, Event::KeyboardZeroPound,
238};
239
240// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
241static const Event::EventSet RightKeypadEvents = {
242 Event::KeyboardOne1, Event::KeyboardOne2, Event::KeyboardOne3,
243 Event::KeyboardOne4, Event::KeyboardOne5, Event::KeyboardOne6,
244 Event::KeyboardOne7, Event::KeyboardOne8, Event::KeyboardOne9,
245 Event::KeyboardOneStar, Event::KeyboardOne0, Event::KeyboardOnePound,
246};
247
248#endif
249