19 getCommandController(),
tmpStrCat(getName(),
" output"),
20 "name of the file the debug-device outputs to",
21 config.getChildData(
"filename",
"stdout"))
24 reset(EmuTime::dummy());
35 if (
const auto& newName = fileNameSetting.
getString();
36 newName != fileNameString) {
40 switch (port & 0x01) {
42 switch ((value & 0x30) >> 4) {
48 modeParameter = value & 0x0F;
52 modeParameter = value & 0x03;
58 (*outputStrm) <<
'\n' << std::flush;
66 outputSingleByte(value, time);
69 outputMultiByte(value);
78void DebugDevice::outputSingleByte(
byte value, EmuTime::param time)
80 if (modeParameter & 0x01) {
81 displayByte(value, HEX);
83 if (modeParameter & 0x02) {
84 displayByte(value, BIN);
86 if (modeParameter & 0x04) {
87 displayByte(value, DEC);
89 if (modeParameter & 0x08) {
90 (*outputStrm) <<
'\'';
91 byte tmp = ((value >=
' ') && (value != 127)) ? value :
'.';
92 displayByte(tmp, ASC);
93 (*outputStrm) <<
"' ";
95 Clock<3579545> zero(EmuTime::zero());
96 (*outputStrm) <<
"emutime: " << std::dec << zero.getTicksTill(time);
97 if ((modeParameter & 0x08) && ((value <
' ') || (value == 127))) {
98 displayByte(value, ASC);
100 (*outputStrm) <<
'\n' << std::flush;
103void DebugDevice::outputMultiByte(
byte value)
105 DisplayType dispType = [&] {
106 switch (modeParameter) {
114 displayByte(value, dispType);
117void DebugDevice::displayByte(
byte value, DisplayType type)
121 (*outputStrm) << std::hex << std::setw(2)
123 << int(value) <<
"h " << std::flush;
126 for (
byte mask = 0x80; mask; mask >>= 1) {
127 (*outputStrm) << ((value & mask) ?
'1' :
'0');
129 (*outputStrm) <<
"b " << std::flush;
133 (*outputStrm) << std::dec << std::setw(3)
135 << int(value) <<
' ' << std::flush;
138 (*outputStrm).put(narrow_cast<char>(value));
139 (*outputStrm) << std::flush;
144void DebugDevice::openOutput(std::string_view name)
146 fileNameString = name;
148 if (name ==
"stdout") {
149 outputStrm = &std::cout;
150 }
else if (name ==
"stderr") {
151 outputStrm = &std::cerr;
155 outputStrm = &debugOut;
159static constexpr std::initializer_list<enum_string<DebugDevice::DebugMode>> debugModeInfo = {
167template<
typename Archive>
170 ar.template serializeBase<MSXDevice>(*
this);
171 ar.serialize(
"mode", mode,
172 "modeParameter", modeParameter);
#define REGISTER_MSXDEVICE(CLASS, NAME)
void reset(EmuTime::param time) override
This method is called on reset.
DebugDevice(const DeviceConfig &config)
void serialize(Archive &ar, unsigned version)
void writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
zstring_view getString() const noexcept
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
string expandTilde(string path)
Expand the '~' character to the users home directory.
void openOfStream(std::ofstream &stream, zstring_view filename)
Open an ofstream in a platform-independent manner.
This file implemented 3 utility functions:
uint16_t word
16 bit unsigned integer
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
#define SERIALIZE_ENUM(TYPE, INFO)
TemporaryString tmpStrCat(Ts &&... ts)