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
12
FirmwareSwitch::FirmwareSwitch
(
const
DeviceConfig
& config_)
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
),
22
File::LOAD_PERSISTENT
);
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
32
FirmwareSwitch::~FirmwareSwitch
()
33
{
34
// save firmware switch setting value to persistent data
35
try
{
36
File
file(config.
getFileContext
().
resolveCreate
(
filename
),
37
File::SAVE_PERSISTENT
);
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
CliComm.hh
FileContext.hh
FileException.hh
File.hh
FirmwareSwitch.hh
openmsx::BooleanSetting::getBoolean
bool getBoolean() const noexcept
Definition:
BooleanSetting.hh:17
openmsx::BooleanSetting::setBoolean
void setBoolean(bool b)
Definition:
BooleanSetting.hh:20
openmsx::CliComm::printWarning
void printWarning(std::string_view message)
Definition:
CliComm.cc:10
openmsx::DeviceConfig
Definition:
DeviceConfig.hh:20
openmsx::DeviceConfig::getCliComm
CliComm & getCliComm() const
Definition:
DeviceConfig.cc:18
openmsx::DeviceConfig::getFileContext
const FileContext & getFileContext() const
Definition:
DeviceConfig.cc:9
openmsx::FileContext::resolveCreate
std::string resolveCreate(std::string_view filename) const
Definition:
FileContext.cc:87
openmsx::FileException
Definition:
FileException.hh:9
openmsx::File
Definition:
File.hh:16
openmsx::File::read
void read(void *buffer, size_t num)
Read from file.
Definition:
File.cc:93
openmsx::File::write
void write(const void *buffer, size_t num)
Write to file.
Definition:
File.cc:98
openmsx::File::SAVE_PERSISTENT
@ SAVE_PERSISTENT
Definition:
File.hh:23
openmsx::File::LOAD_PERSISTENT
@ LOAD_PERSISTENT
Definition:
File.hh:22
openmsx::FirmwareSwitch::FirmwareSwitch
FirmwareSwitch(const DeviceConfig &config)
Definition:
FirmwareSwitch.cc:12
openmsx::FirmwareSwitch::~FirmwareSwitch
~FirmwareSwitch()
Definition:
FirmwareSwitch.cc:32
openmsx::MSXException::getMessage
const std::string & getMessage() const &
Definition:
MSXException.hh:23
openmsx::Setting
Definition:
Setting.hh:127
openmsx
This file implemented 3 utility functions:
Definition:
Autofire.cc:5
openmsx::filename
constexpr const char *const filename
Definition:
FirmwareSwitch.cc:10
openmsx.hh
Generated on Sat Jan 23 2021 17:16:41 for openMSX by
1.9.1