openMSX
PrinterPortLogger.cc
Go to the documentation of this file.
2#include "PlugException.hh"
3#include "FileContext.hh"
4#include "FileException.hh"
5#include "serialize.hh"
6
7namespace openmsx {
8
10 : logFilenameSetting(
11 commandController, "printerlogfilename",
12 "filename of the file where the printer output is logged to",
13 "printer.log")
14{
15}
16
17bool PrinterPortLogger::getStatus(EmuTime::param /*time*/)
18{
19 return false; // false = low = ready
20}
21
22void PrinterPortLogger::setStrobe(bool strobe, EmuTime::param /*time*/)
23{
24 if (file.is_open() && !strobe && prevStrobe) {
25 // falling edge
26 file.write(std::span{&toPrint, 1});
27 file.flush(); // optimize when it turns out flushing
28 // every time is too slow
29 }
30 prevStrobe = strobe;
31}
32
33void PrinterPortLogger::writeData(uint8_t data, EmuTime::param /*time*/)
34{
35 toPrint = data;
36}
37
39 Connector& /*connector*/, EmuTime::param /*time*/)
40{
41 try {
42 file = File(userFileContext().resolve(logFilenameSetting.getString()),
44 } catch (FileException& e) {
45 throw PlugException("Couldn't plug printer logger: ",
46 e.getMessage());
47 }
48}
49
50void PrinterPortLogger::unplugHelper(EmuTime::param /*time*/)
51{
52 file.close();
53}
54
55std::string_view PrinterPortLogger::getName() const
56{
57 return "logger";
58}
59
60std::string_view PrinterPortLogger::getDescription() const
61{
62 return "Log everything that is sent to the printer port to a "
63 "file. The filename can be set with the "
64 "'printerlogfilename' setting.";
65}
66
67template<typename Archive>
68void PrinterPortLogger::serialize(Archive& /*ar*/, unsigned /*version*/)
69{
70 // We don't try to resume logging to the same file.
71 // And to not accidentally loose a previous log, we don't
72 // overwrite that file automatically. So after savestate/loadstate,
73 // you have to replug the PrinterPortLogger
74}
77
78} // namespace openmsx
Represents something you can plug devices into.
Definition Connector.hh:21
void close()
Close the current file.
Definition File.cc:87
void write(std::span< const uint8_t > buffer)
Write to file.
Definition File.cc:97
bool is_open() const
Return true iff this file handle refers to an open file.
Definition File.hh:65
void flush()
Force a write of all buffered data to disk.
Definition File.cc:132
zstring_view getString() const noexcept
Thrown when a plug action fails.
void unplugHelper(EmuTime::param time) override
void setStrobe(bool strobe, EmuTime::param time) override
Sets the strobe signal: false = low, true = high.
void serialize(Archive &ar, unsigned version)
void plugHelper(Connector &connector, EmuTime::param time) override
PrinterPortLogger(CommandController &commandController)
std::string_view getName() const override
Name used to identify this pluggable.
void writeData(uint8_t data, EmuTime::param time) override
Sets the data signals.
bool getStatus(EmuTime::param time) override
Returns the STATUS signal: false = low = ready, true = high = not ready.
std::string_view getDescription() const override
Description for this pluggable.
This file implemented 3 utility functions:
Definition Autofire.cc:11
const FileContext & userFileContext()
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
#define REGISTER_POLYMORPHIC_INITIALIZER(BASE, CLASS, NAME)