diff --git a/Includes/CardIo.cpp b/Includes/CardIo.cpp index 20a4c44..f9d4cb2 100755 --- a/Includes/CardIo.cpp +++ b/Includes/CardIo.cpp @@ -317,6 +317,9 @@ void CardIo::Command_78_PrintSettings2() { status.SoftReset(); runningCommand = false; + + if (currentPacket.size() >= 2) + m_printer->SetPrintMethod(currentPacket[1]); } void CardIo::Command_7A_RegisterFont() diff --git a/Includes/Printer.cpp b/Includes/Printer.cpp index 70fd787..7714f4a 100644 --- a/Includes/Printer.cpp +++ b/Includes/Printer.cpp @@ -75,15 +75,21 @@ bool Printer::QueuePrintLine(std::vector& data) Append = '1', }; - if (m_cardImage == nullptr) - LoadCardImage(m_localName); - // Microsoft in their infinite wisdom defines min in windows.h, so we can't use std::min constexpr uint8_t maxOffset = 0x14; const uint8_t offset = data[2] < maxOffset ? data[2] : maxOffset; - if (static_cast(data[1]) == BufferControl::Clear) + bool skip_printed_image = false; + if (static_cast(data[1]) == BufferControl::Clear) { + if (m_eraseOnClear) { + Erase(); + skip_printed_image = true; + } m_printQueue.clear(); + } + + if (m_cardImage == nullptr) + LoadCardImage(m_localName, skip_printed_image); std::vector temp = {}; std::copy(data.begin() + 3, data.end(), std::back_inserter(temp)); diff --git a/Includes/Printer.h b/Includes/Printer.h index 28e1944..7e2543a 100644 --- a/Includes/Printer.h +++ b/Includes/Printer.h @@ -74,6 +74,7 @@ class Printer m_cardImage = nullptr; } m_localName = ""; + m_eraseOnClear = false; } void Erase() @@ -83,6 +84,11 @@ class Printer m_cardImage = nullptr; } } + + void SetPrintMethod(uint8_t method) { + m_eraseOnClear = method == 0x30; + g_logger->trace("Printer::SetPrintMethod: m_eraseOnClear = {}", m_eraseOnClear); + } bool RegisterFont(std::vector& data); bool QueuePrintLine(std::vector& data); @@ -102,20 +108,24 @@ class Printer std::vector m_printQueue = {}; std::vector m_customGlyphs = {}; + bool m_eraseOnClear = false; + SDL_Surface* m_cardImage = nullptr; void PrintLine(); - void LoadCardImage(std::string& cardName) + void LoadCardImage(std::string& cardName, bool skip_printed_image = false) { - std::string temp = cardName; - temp.append(".png"); - - if (ghc::filesystem::exists(temp)) { - m_cardImage = IMG_Load(temp.c_str()); - if (m_cardImage != nullptr) - return; - g_logger->warn("Printer::LoadCardImage: Found card image but IMG_Load couldn't create the surface, generating a transparent surface"); + if (!skip_printed_image) { + std::string temp = cardName; + temp.append(".png"); + + if (ghc::filesystem::exists(temp)) { + m_cardImage = IMG_Load(temp.c_str()); + if (m_cardImage != nullptr) + return; + g_logger->warn("Printer::LoadCardImage: Found card image but IMG_Load couldn't create the surface, generating a transparent surface"); + } } std::string cwd = ghc::filesystem::current_path().string();