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#include "Event.hxx"
19#include "Props.hxx"
20#include "Settings.hxx"
21#include "Switches.hxx"
22
23// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
24Switches::Switches(const Event& event, const Properties& properties,
25 const Settings& settings)
26 : myEvent(event),
27 mySwitches(0xFF),
28 myIs7800(false)
29{
30 if(properties.get(PropType::Console_RightDiff) == "B")
31 {
32 mySwitches &= ~0x80;
33 }
34 else
35 {
36 mySwitches |= 0x80;
37 }
38
39 if(properties.get(PropType::Console_LeftDiff) == "B")
40 {
41 mySwitches &= ~0x40;
42 }
43 else
44 {
45 mySwitches |= 0x40;
46 }
47
48 if(properties.get(PropType::Console_TVType) == "COLOR")
49 {
50 mySwitches |= 0x08;
51 }
52 else
53 {
54 mySwitches &= ~0x08;
55 }
56
57 check7800Mode(settings);
58}
59
60// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
61void Switches::update()
62{
63 if(myIs7800)
64 {
65 if(myEvent.get(Event::Console7800Pause) != 0)
66 {
67 mySwitches &= ~0x08;
68 }
69 else
70 {
71 mySwitches |= 0x08;
72 }
73 }
74
75 if(myEvent.get(Event::ConsoleColor) != 0)
76 {
77 mySwitches |= 0x08;
78 }
79 else if(myEvent.get(Event::ConsoleBlackWhite) != 0)
80 {
81 mySwitches &= ~0x08;
82 }
83
84 if(myEvent.get(Event::ConsoleRightDiffA) != 0)
85 {
86 mySwitches |= 0x80;
87 }
88 else if(myEvent.get(Event::ConsoleRightDiffB) != 0)
89 {
90 mySwitches &= ~0x80;
91 }
92
93 if(myEvent.get(Event::ConsoleLeftDiffA) != 0)
94 {
95 mySwitches |= 0x40;
96 }
97 else if(myEvent.get(Event::ConsoleLeftDiffB) != 0)
98 {
99 mySwitches &= ~0x40;
100 }
101
102 if(myEvent.get(Event::ConsoleSelect) != 0)
103 {
104 mySwitches &= ~0x02;
105 }
106 else
107 {
108 mySwitches |= 0x02;
109 }
110
111 if(myEvent.get(Event::ConsoleReset) != 0)
112 {
113 mySwitches &= ~0x01;
114 }
115 else
116 {
117 mySwitches |= 0x01;
118 }
119}
120
121// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
122void Switches::setTvColor(bool setColor)
123{
124 if(setColor)
125 {
126 mySwitches |= 0x08;
127 }
128 else
129 {
130 mySwitches &= ~0x08;
131 }
132}
133
134// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
135void Switches::setLeftDifficultyA(bool setToA)
136{
137 if(setToA)
138 {
139 mySwitches |= 0x40;
140 }
141 else
142 {
143 mySwitches &= ~0x40;
144 }
145}
146
147// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
148void Switches::setRightDifficultyA(bool setToA)
149{
150 if(setToA)
151 {
152 mySwitches |= 0x80;
153 }
154 else
155 {
156 mySwitches &= ~0x80;
157 }
158}
159
160// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
161bool Switches::save(Serializer& out) const
162{
163 try
164 {
165 out.putByte(mySwitches);
166 }
167 catch(...)
168 {
169 cerr << "ERROR: Switches::save() exception\n";
170 return false;
171 }
172 return true;
173}
174
175// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
176bool Switches::load(Serializer& in)
177{
178 try
179 {
180 mySwitches = in.getByte();
181 }
182 catch(...)
183 {
184 cerr << "ERROR: Switches::load() exception\n";
185 return false;
186 }
187 return true;
188}
189
190// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
191bool Switches::check7800Mode(const Settings& settings)
192{
193 bool devSettings = settings.getBool("dev.settings");
194 myIs7800 = (settings.getString(devSettings ? "dev.console" : "plr.console") == "7800");
195
196 return myIs7800;
197}
198