| 1 |
#include "PrinterPortLogger.hh" |
| 2 |
|
| 3 |
#include "FileContext.hh" |
| 4 |
#include "FileException.hh" |
| 5 |
#include "PlugException.hh" |
| 6 |
#include "serialize.hh" |
| 7 |
|
| 8 |
namespace openmsx { |
| 9 |
|
| 10 |
PrinterPortLogger::PrinterPortLogger(CommandController& commandController) |
| 11 |
: logFilenameSetting( |
| 12 |
commandController, "printerlogfilename", |
| 13 |
"filename of the file where the printer output is logged to", |
| 14 |
"printer.log") |
| 15 |
{ |
| 16 |
} |
| 17 |
|
| 18 |
bool PrinterPortLogger::getStatus(EmuTime ) |
| 19 |
{ |
| 20 |
return false; |
| 21 |
} |
| 22 |
|
| 23 |
void PrinterPortLogger::setStrobe(bool strobe, EmuTime ) |
| 24 |
{ |
| 25 |
if (file.is_open() && !strobe && prevStrobe) { |
| 26 |
|
| 27 |
file.write(std::span{&toPrint, 1}); |
| 28 |
file.flush(); |
| 29 |
|
| 30 |
} |
| 31 |
prevStrobe = strobe; |
| 32 |
} |
| 33 |
|
| 34 |
void PrinterPortLogger::writeData(uint8_t data, EmuTime ) |
| 35 |
{ |
| 36 |
toPrint = data; |
| 37 |
} |
| 38 |
|
| 39 |
void PrinterPortLogger::plugHelper( |
| 40 |
Connector& , EmuTime ) |
| 41 |
{ |
| 42 |
try { |
| 43 |
file = File(userFileContext().resolve(logFilenameSetting.getString()), |
| 44 |
File::OpenMode::TRUNCATE); |
| 45 |
} catch (FileException& e) { |
| 46 |
throw PlugException("Couldn't plug printer logger: ", |
| 47 |
e.getMessage()); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
void PrinterPortLogger::unplugHelper(EmuTime ) |
| 52 |
{ |
| 53 |
file.close(); |
| 54 |
} |
| 55 |
|
| 56 |
zstring_view PrinterPortLogger::getName() const |
| 57 |
{ |
| 58 |
return "logger"; |
| 59 |
} |
| 60 |
|
| 61 |
zstring_view PrinterPortLogger::getDescription() const |
| 62 |
{ |
| 63 |
return "Log everything that is sent to the printer port to a " |
| 64 |
"file. The filename can be set with the " |
| 65 |
"'printerlogfilename' setting."; |
| 66 |
} |
| 67 |
|
| 68 |
template<typename Archive> |
| 69 |
void PrinterPortLogger::serialize(Archive& , unsigned ) |
| 70 |
{ |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
} |
| 76 |
INSTANTIATE_SERIALIZE_METHODS(PrinterPortLogger); |
| 77 |
REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, PrinterPortLogger, "PrinterPortLogger"); |
| 78 |
|
| 79 |
} |