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 <array>
7
#include <cstdint>
8
9
namespace
openmsx
{
10
11
static
constexpr
const
char
*
const
filename =
"firmwareswitch"
;
12
13
FirmwareSwitch::FirmwareSwitch
(
const
DeviceConfig
& config_)
14
: config(config_)
15
,
setting
(
16
config.getCommandController(),
"firmwareswitch"
,
17
"This setting controls the firmware switch"
,
18
false,
Setting
::DONT_SAVE)
19
{
20
// load firmware switch setting from persistent data
21
try
{
22
File
file(config.
getFileContext
().
resolveCreate
(filename),
23
File::LOAD_PERSISTENT
);
24
std::array<uint8_t, 1> byteBuf;
25
file.
read
(byteBuf);
26
setting.
setBoolean
(byteBuf[0] != 0);
27
}
catch
(
FileException
&
e
) {
28
config.
getCliComm
().
printWarning
(
29
"Couldn't load firmwareswitch status: "
,
e
.getMessage());
30
}
31
}
32
33
FirmwareSwitch::~FirmwareSwitch
()
34
{
35
// save firmware switch setting value to persistent data
36
try
{
37
File
file(config.
getFileContext
().
resolveCreate
(filename),
38
File::SAVE_PERSISTENT
);
39
std::array byteBuf = {uint8_t(setting.
getBoolean
() ? 0xFF : 0x00)};
40
file.
write
(byteBuf);
41
}
catch
(
FileException
&
e
) {
42
config.
getCliComm
().
printWarning
(
43
"Couldn't save firmwareswitch status: "
,
e
.getMessage());
44
}
45
}
46
47
}
// namespace openmsx
CliComm.hh
FileContext.hh
FileException.hh
File.hh
FirmwareSwitch.hh
setting
BaseSetting * setting
Definition:
Interpreter.cc:28
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:21
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:86
openmsx::FileException
Definition:
FileException.hh:9
openmsx::File
Definition:
File.hh:16
openmsx::File::read
void read(std::span< uint8_t > buffer)
Read from file.
Definition:
File.cc:92
openmsx::File::write
void write(std::span< const uint8_t > buffer)
Write to file.
Definition:
File.cc:97
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:13
openmsx::FirmwareSwitch::~FirmwareSwitch
~FirmwareSwitch()
Definition:
FirmwareSwitch.cc:33
openmsx::Setting
Definition:
Setting.hh:127
Math::e
constexpr double e
Definition:
Math.hh:21
openmsx
This file implemented 3 utility functions:
Definition:
Autofire.cc:9
Generated on Fri May 19 2023 13:13:11 for openMSX by
1.9.4