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
8namespace openmsx {
9
10constexpr 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[1];
24 file.read(bytebuf, 1);
25 setting.setBoolean(bytebuf[0] != 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
BaseSetting * setting
Definition: Interpreter.cc:27
bool getBoolean() const noexcept
void printWarning(std::string_view message)
Definition: CliComm.cc:10
CliComm & getCliComm() const
Definition: DeviceConfig.cc:18
const FileContext & getFileContext() const
Definition: DeviceConfig.cc:9
std::string resolveCreate(std::string_view filename) const
Definition: FileContext.cc:86
void read(void *buffer, size_t num)
Read from file.
Definition: File.cc:91
void write(const void *buffer, size_t num)
Write to file.
Definition: File.cc:96
@ SAVE_PERSISTENT
Definition: File.hh:23
@ LOAD_PERSISTENT
Definition: File.hh:22
FirmwareSwitch(const DeviceConfig &config)
constexpr double e
Definition: Math.hh:18
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename