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