forked from stella-emu/stella
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSwitches.cxx
227 lines (206 loc) · 4.34 KB
/
Switches.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2024 by Bradford W. Mott, Stephen Anthony
// and the Stella Team
//
// See the file "License.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#include "Event.hxx"
#include "Props.hxx"
#include "Settings.hxx"
#include "Switches.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Switches::Switches(const Event& event, const Properties& props,
const Settings& settings)
: myEvent{event}
{
if(props.get(PropType::Console_RightDiff) == "B")
{
mySwitches &= ~0x80;
}
else
{
mySwitches |= 0x80;
}
if(props.get(PropType::Console_LeftDiff) == "B")
{
mySwitches &= ~0x40;
}
else
{
mySwitches |= 0x40;
}
if(props.get(PropType::Console_TVType) == "COLOR")
{
mySwitches |= 0x08;
}
else
{
mySwitches &= ~0x08;
}
check7800Mode(settings);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Switches::update()
{
if(myIs7800)
{
if(myEvent.get(Event::Console7800Pause) != 0)
{
mySwitches &= ~0x08;
}
else
{
mySwitches |= 0x08;
}
}
if(myEvent.get(Event::ConsoleColor) != 0)
{
mySwitches |= 0x08;
}
else if(myEvent.get(Event::ConsoleBlackWhite) != 0)
{
mySwitches &= ~0x08;
}
if(myEvent.get(Event::ConsoleRightDiffA) != 0)
{
mySwitches |= 0x80;
}
else if(myEvent.get(Event::ConsoleRightDiffB) != 0)
{
mySwitches &= ~0x80;
}
if(myEvent.get(Event::ConsoleLeftDiffA) != 0)
{
mySwitches |= 0x40;
}
else if(myEvent.get(Event::ConsoleLeftDiffB) != 0)
{
mySwitches &= ~0x40;
}
if(myEvent.get(Event::ConsoleSelect) != 0)
{
mySwitches &= ~0x02;
}
else
{
mySwitches |= 0x02;
}
if(myEvent.get(Event::ConsoleReset) != 0)
{
mySwitches &= ~0x01;
}
else
{
mySwitches |= 0x01;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Switches::setTvColor(bool setColor)
{
if(setColor)
{
mySwitches |= 0x08;
}
else
{
mySwitches &= ~0x08;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Switches::setLeftDifficultyA(bool setToA)
{
if(setToA)
{
mySwitches |= 0x40;
}
else
{
mySwitches &= ~0x40;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Switches::setRightDifficultyA(bool setToA)
{
if(setToA)
{
mySwitches |= 0x80;
}
else
{
mySwitches &= ~0x80;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Switches::setReset(bool setToA)
{
if(setToA)
{
mySwitches |= 0x01;
}
else
{
mySwitches &= ~0x01;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Switches::setSelect(bool setSel)
{
if(setSel)
{
mySwitches |= 0x02;
}
else
{
mySwitches &= ~0x02;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Switches::clear()
{
mySwitches = 0;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Switches::save(Serializer& out) const
{
try
{
out.putByte(mySwitches);
}
catch(...)
{
cerr << "ERROR: Switches::save() exception\n";
return false;
}
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Switches::load(Serializer& in)
{
try
{
mySwitches = in.getByte();
}
catch(...)
{
cerr << "ERROR: Switches::load() exception\n";
return false;
}
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Switches::check7800Mode(const Settings& settings)
{
const bool devSettings = settings.getBool("dev.settings");
myIs7800 = (settings.getString(devSettings ? "dev.console" : "plr.console") == "7800");
return myIs7800;
}