openMSX
FirmwareSwitch.cc
Go to the documentation of this file.
1 #include "FirmwareSwitch.hh"
2 #include "CliComm.hh"
3 #include "FileContext.hh"
4 #include "File.hh"
5 #include "FileException.hh"
6 #include "openmsx.hh"
7 
8 namespace openmsx {
9 
10 constexpr const char* const filename = "firmwareswitch";
11 
13  : config(config_)
14  , setting(
15  config.getCommandController(), "firmwareswitch",
16  "This setting controls the firmware switch",
17  false, Setting::DONT_SAVE)
18 {
19  // load firmware switch setting from persistent data
20  try {
23  byte bytebuf;
24  file.read(&bytebuf, 1);
25  setting.setBoolean(bytebuf != 0);
26  } catch (FileException& e) {
27  config.getCliComm().printWarning(
28  "Couldn't load firmwareswitch status: ", e.getMessage());
29  }
30 }
31 
33 {
34  // save firmware switch setting value to persistent data
35  try {
38  byte bytebuf = setting.getBoolean() ? 0xFF : 0x00;
39  file.write(&bytebuf, 1);
40  } catch (FileException& e) {
41  config.getCliComm().printWarning(
42  "Couldn't save firmwareswitch status: ", e.getMessage());
43  }
44 }
45 
46 } // namespace openmsx
FileException.hh
openmsx.hh
openmsx::DeviceConfig
Definition: DeviceConfig.hh:19
openmsx::FileContext::resolveCreate
std::string resolveCreate(std::string_view filename) const
Definition: FileContext.cc:85
openmsx::FirmwareSwitch::FirmwareSwitch
FirmwareSwitch(const DeviceConfig &config)
Definition: FirmwareSwitch.cc:12
openmsx::Setting
Definition: Setting.hh:119
openmsx::DeviceConfig::getCliComm
CliComm & getCliComm() const
Definition: DeviceConfig.cc:18
openmsx::FirmwareSwitch::~FirmwareSwitch
~FirmwareSwitch()
Definition: FirmwareSwitch.cc:32
openmsx::CliComm::printWarning
void printWarning(std::string_view message)
Definition: CliComm.cc:10
FirmwareSwitch.hh
File.hh
openmsx::filename
constexpr const char *const filename
Definition: FirmwareSwitch.cc:10
openmsx::FileException
Definition: FileException.hh:8
openmsx::File::SAVE_PERSISTENT
Definition: File.hh:23
FileContext.hh
openmsx::File
Definition: File.hh:15
openmsx::File::LOAD_PERSISTENT
Definition: File.hh:22
openmsx::File::read
void read(void *buffer, size_t num)
Read from file.
Definition: File.cc:83
openmsx::DeviceConfig::getFileContext
const FileContext & getFileContext() const
Definition: DeviceConfig.cc:9
CliComm.hh
openmsx::MSXException::getMessage
const std::string & getMessage() const &
Definition: MSXException.hh:23
openmsx::BooleanSetting::setBoolean
void setBoolean(bool b)
Definition: BooleanSetting.hh:18
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::BooleanSetting::getBoolean
bool getBoolean() const noexcept
Definition: BooleanSetting.hh:17