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 static 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 {
21  File file(config.getFileContext().resolveCreate(filename),
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 {
36  File file(config.getFileContext().resolveCreate(filename),
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
std::string resolveCreate(string_view filename) const
Definition: FileContext.cc:84
const std::string & getMessage() const &
Definition: MSXException.hh:23
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
const FileContext & getFileContext() const
Definition: DeviceConfig.cc:9
FirmwareSwitch(const DeviceConfig &config)
CliComm & getCliComm() const
Definition: DeviceConfig.cc:18
bool getBoolean() const noexcept
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void read(void *buffer, size_t num)
Read from file.
Definition: File.cc:83
void printWarning(string_view message)
Definition: CliComm.cc:20