openMSX
Printer.hh
Go to the documentation of this file.
1
10#ifndef PRINTER_HH
11#define PRINTER_HH
12
13#include "PrinterPortDevice.hh"
14#include <array>
15#include <memory>
16#include <utility>
17
18namespace openmsx {
19
20class MSXMotherBoard;
21class IntegerSetting;
22class Paper;
23
24
25// Abstract printer class
27{
28public:
29 // PrinterPortDevice
30 [[nodiscard]] bool getStatus(EmuTime::param time) override;
31 void setStrobe(bool strobe, EmuTime::param time) override;
32 void writeData(uint8_t data, EmuTime::param time) override;
33
34 // Pluggable
35 void plugHelper(Connector& connector, EmuTime::param time) override;
36 void unplugHelper(EmuTime::param time) override;
37
38protected:
39 PrinterCore() = default;
40 ~PrinterCore() override = default;
41 virtual void write(uint8_t data) = 0;
42 virtual void forceFormFeed() = 0;
43
44private:
45 uint8_t toPrint = 0;
46 bool prevStrobe = true;
47};
48
49
50// Abstract image printer
52{
53public:
54 void write(uint8_t data) override;
55 void forceFormFeed() override;
56
57protected:
58 ImagePrinter(MSXMotherBoard& motherBoard, bool graphicsHiLo);
59 ~ImagePrinter() override;
60
62 void printGraphicByte(uint8_t data);
63 void seekPrinterHeadRelative(double offset);
64 void ensurePrintPage();
66 void printVisibleCharacter(uint8_t data);
67 void plot9Dots(double x, double y, unsigned pattern);
68
69 [[nodiscard]] virtual std::pair<unsigned, unsigned> getNumberOfDots() = 0;
70 virtual void resetSettings() = 0;
71 [[nodiscard]] virtual unsigned calcEscSequenceLength(uint8_t character) = 0;
72 virtual void processEscSequence() = 0;
73 virtual void processCharacter(uint8_t data) = 0;
74
75protected:
76 static constexpr unsigned PIXEL_WIDTH = 8;
77
80 double hpos;
81 double vpos;
82 double pageTop;
83 double lineFeed;
84 double pageHeight;
85 double printAreaTop = -1.0;
86 double printAreaBottom = 0.0;
87 double pixelSizeX;
88 double pixelSizeY;
89 int eightBit = 0;
90 unsigned perforationSkip = 0;
91 unsigned leftBorder;
92 unsigned rightBorder;
93 unsigned fontWidth;
95 unsigned sizeEscPos = 0;
97 unsigned ramLoadOffset = 0;
98 unsigned ramLoadEnd = 0;
99 unsigned lines;
112
113 static constexpr int MAX_ESC_CMDSIZE = 8;
114 std::array<uint8_t, MAX_ESC_CMDSIZE> abEscSeq;
115
116 static constexpr int MAX_FONT_WIDTH = 12;
117 struct FontInfo {
118 std::array<uint8_t, 256 * MAX_FONT_WIDTH> rom;
119 std::array<uint8_t, 256 * MAX_FONT_WIDTH> ram;
121 unsigned charWidth;
122 bool useRam;
124
125 bool letterQuality = false;
126 bool bold = false;
127 bool proportional = false;
128 bool italic = false;
129 bool superscript = false;
130 bool subscript = false;
131 bool doubleWidth = false;
132 bool underline = false;
133 bool doubleStrike = false;
134 bool escSequence = false;
135 bool alternateChar = false;
136 bool detectPaperOut = false;
137 bool japanese = false;
138 bool normalAfterLine = false;
139 bool ninePinGraphics = false;
140 bool leftToRight = false;
141 bool elite = false;
142 bool compressed = false;
143 bool noHighEscapeCodes = false;
144
145private:
146 MSXMotherBoard& motherBoard;
147 std::unique_ptr<Paper> paper;
148
149 std::shared_ptr<IntegerSetting> dpiSetting;
150
151 const bool graphicsHiLo;
152};
153
154// emulated MSX printer
155class ImagePrinterMSX final : public ImagePrinter
156{
157public:
158 explicit ImagePrinterMSX(MSXMotherBoard& motherBoard);
159
160 // Pluggable
161 [[nodiscard]] std::string_view getName() const override;
162 [[nodiscard]] std::string_view getDescription() const override;
163
164 template<typename Archive>
165 void serialize(Archive& ar, unsigned version);
166
167private:
168 [[nodiscard]] unsigned parseNumber(unsigned sizeStart, unsigned sizeChars);
169
170 [[nodiscard]] std::pair<unsigned, unsigned> getNumberOfDots() override;
171 void resetSettings() override;
172 [[nodiscard]] unsigned calcEscSequenceLength(uint8_t character) override;
173 void processEscSequence() override;
174 void processCharacter(uint8_t data) override;
175};
176
177// emulated Epson printer
178class ImagePrinterEpson final : public ImagePrinter
179{
180public:
181 explicit ImagePrinterEpson(MSXMotherBoard& motherBoard);
182
183 // Pluggable
184 [[nodiscard]] std::string_view getName() const override;
185 [[nodiscard]] std::string_view getDescription() const override;
186
187 template<typename Archive>
188 void serialize(Archive& ar, unsigned version);
189
190private:
191 [[nodiscard]] unsigned parseNumber(unsigned sizeStart, unsigned sizeChars);
192
193 [[nodiscard]] std::pair<unsigned, unsigned> getNumberOfDots() override;
194 void resetSettings() override;
195 [[nodiscard]] unsigned calcEscSequenceLength(uint8_t character) override;
196 void processEscSequence() override;
197 void processCharacter(uint8_t data) override;
198};
199
200} // namespace openmsx
201
202#endif
Represents something you can plug devices into.
Definition Connector.hh:21
std::string_view getName() const override
Name used to identify this pluggable.
Definition Printer.cc:1143
void serialize(Archive &ar, unsigned version)
Definition Printer.cc:1575
std::string_view getDescription() const override
Description for this pluggable.
Definition Printer.cc:1148
std::string_view getDescription() const override
Description for this pluggable.
Definition Printer.cc:604
void serialize(Archive &ar, unsigned version)
Definition Printer.cc:868
std::string_view getName() const override
Name used to identify this pluggable.
Definition Printer.cc:599
virtual unsigned calcEscSequenceLength(uint8_t character)=0
void seekPrinterHeadRelative(double offset)
Definition Printer.cc:180
void resetEmulatedPrinter()
Definition Printer.cc:142
virtual std::pair< unsigned, unsigned > getNumberOfDots()=0
unsigned remainingCommandBytes
Definition Printer.hh:94
std::array< uint8_t, MAX_ESC_CMDSIZE > abEscSeq
Definition Printer.hh:114
virtual void processCharacter(uint8_t data)=0
void plot9Dots(double x, double y, unsigned pattern)
Definition Printer.cc:151
~ImagePrinter() override
Definition Printer.cc:97
static constexpr int MAX_ESC_CMDSIZE
Definition Printer.hh:113
unsigned sizeRemainingDataBytes
Definition Printer.hh:96
virtual void resetSettings()=0
void printVisibleCharacter(uint8_t data)
Definition Printer.cc:242
void forceFormFeed() override
Definition Printer.cc:137
static constexpr unsigned PIXEL_WIDTH
Definition Printer.hh:76
struct openmsx::ImagePrinter::FontInfo fontInfo
virtual void processEscSequence()=0
unsigned perforationSkip
Definition Printer.hh:90
static constexpr int MAX_FONT_WIDTH
Definition Printer.hh:116
void flushEmulatedPrinter()
Definition Printer.cc:211
void write(uint8_t data) override
Definition Printer.cc:102
CountryCode countryCode
Definition Printer.hh:111
unsigned ramLoadOffset
Definition Printer.hh:97
void printGraphicByte(uint8_t data)
Definition Printer.cc:160
void writeData(uint8_t data, EmuTime::param time) override
Sets the data signals.
Definition Printer.cc:68
void setStrobe(bool strobe, EmuTime::param time) override
Sets the strobe signal: false = low, true = high.
Definition Printer.cc:59
virtual void forceFormFeed()=0
void plugHelper(Connector &connector, EmuTime::param time) override
Definition Printer.cc:73
virtual void write(uint8_t data)=0
void unplugHelper(EmuTime::param time) override
Definition Printer.cc:78
bool getStatus(EmuTime::param time) override
Returns the STATUS signal: false = low = ready, true = high = not ready.
Definition Printer.cc:54
~PrinterCore() override=default
This file implemented 3 utility functions:
Definition Autofire.cc:11
std::array< uint8_t, 256 *MAX_FONT_WIDTH > rom
Definition Printer.hh:118
std::array< uint8_t, 256 *MAX_FONT_WIDTH > ram
Definition Printer.hh:119