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// sends data to host printer
51class RawPrinter : public PrinterCore
52{
53public:
54 RawPrinter();
55 ~RawPrinter();
56
57 void write(uint8_t data);
58 void forceFormFeed();
59 // Pluggable
60 [[nodiscard]] std::string_view getName() const override;
61 [[nodiscard]] std::string_view getDescription() const override;
62
63private:
64 HANDLE hFile;
65};
66*/
67
68// Abstract image printer
70{
71public:
72 void write(uint8_t data) override;
73 void forceFormFeed() override;
74
75protected:
76 ImagePrinter(MSXMotherBoard& motherBoard, bool graphicsHiLo);
77 ~ImagePrinter() override;
78
80 void printGraphicByte(uint8_t data);
81 void seekPrinterHeadRelative(double offset);
82 void ensurePrintPage();
84 void printVisibleCharacter(uint8_t data);
85 void plot9Dots(double x, double y, unsigned pattern);
86
87 [[nodiscard]] virtual std::pair<unsigned, unsigned> getNumberOfDots() = 0;
88 virtual void resetSettings() = 0;
89 [[nodiscard]] virtual unsigned calcEscSequenceLength(uint8_t character) = 0;
90 virtual void processEscSequence() = 0;
91 virtual void processCharacter(uint8_t data) = 0;
92
93protected:
94 static constexpr unsigned PIXEL_WIDTH = 8;
95
98 double hpos;
99 double vpos;
100 double pageTop;
101 double lineFeed;
103 double printAreaTop = -1.0;
104 double printAreaBottom = 0.0;
107 int eightBit = 0;
108 unsigned perforationSkip = 0;
109 unsigned leftBorder;
110 unsigned rightBorder;
111 unsigned fontWidth;
113 unsigned sizeEscPos = 0;
115 unsigned ramLoadOffset = 0;
116 unsigned ramLoadEnd = 0;
117 unsigned lines;
127 CC_JAPAN = 8
128 };
130
131 static constexpr int MAX_ESC_CMDSIZE = 8;
132 std::array<uint8_t, MAX_ESC_CMDSIZE> abEscSeq;
133
134 static constexpr int MAX_FONT_WIDTH = 12;
135 struct FontInfo {
136 std::array<uint8_t, 256 * MAX_FONT_WIDTH> rom;
137 std::array<uint8_t, 256 * MAX_FONT_WIDTH> ram;
139 unsigned charWidth;
140 bool useRam;
142
143 bool letterQuality = false;
144 bool bold = false;
145 bool proportional = false;
146 bool italic = false;
147 bool superscript = false;
148 bool subscript = false;
149 bool doubleWidth = false;
150 bool underline = false;
151 bool doubleStrike = false;
152 bool escSequence = false;
153 bool alternateChar = false;
154 bool detectPaperOut = false;
155 bool japanese = false;
156 bool normalAfterLine = false;
157 bool ninePinGraphics = false;
158 bool leftToRight = false;
159 bool elite = false;
160 bool compressed = false;
161 bool noHighEscapeCodes = false;
162
163private:
164 MSXMotherBoard& motherBoard;
165 std::unique_ptr<Paper> paper;
166
167 std::shared_ptr<IntegerSetting> dpiSetting;
168
169 const bool graphicsHiLo;
170};
171
172// emulated MSX printer
173class ImagePrinterMSX final : public ImagePrinter
174{
175public:
176 explicit ImagePrinterMSX(MSXMotherBoard& motherBoard);
177
178 // Pluggable
179 [[nodiscard]] std::string_view getName() const override;
180 [[nodiscard]] std::string_view getDescription() const override;
181
182 template<typename Archive>
183 void serialize(Archive& ar, unsigned version);
184
185private:
186 [[nodiscard]] unsigned parseNumber(unsigned sizeStart, unsigned sizeChars);
187
188 [[nodiscard]] std::pair<unsigned, unsigned> getNumberOfDots() override;
189 void resetSettings() override;
190 [[nodiscard]] unsigned calcEscSequenceLength(uint8_t character) override;
191 void processEscSequence() override;
192 void processCharacter(uint8_t data) override;
193};
194
195// emulated Epson printer
196class ImagePrinterEpson final : public ImagePrinter
197{
198public:
199 explicit ImagePrinterEpson(MSXMotherBoard& motherBoard);
200
201 // Pluggable
202 [[nodiscard]] std::string_view getName() const override;
203 [[nodiscard]] std::string_view getDescription() const override;
204
205 template<typename Archive>
206 void serialize(Archive& ar, unsigned version);
207
208private:
209 [[nodiscard]] unsigned parseNumber(unsigned sizeStart, unsigned sizeChars);
210
211 [[nodiscard]] std::pair<unsigned, unsigned> getNumberOfDots() override;
212 void resetSettings() override;
213 [[nodiscard]] unsigned calcEscSequenceLength(uint8_t character) override;
214 void processEscSequence() override;
215 void processCharacter(uint8_t data) override;
216};
217
218} // namespace openmsx
219
220#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:1165
void serialize(Archive &ar, unsigned version)
Definition: Printer.cc:1597
ImagePrinterEpson(MSXMotherBoard &motherBoard)
Definition: Printer.cc:1159
std::string_view getDescription() const override
Description for this pluggable.
Definition: Printer.cc:1170
std::string_view getDescription() const override
Description for this pluggable.
Definition: Printer.cc:626
void serialize(Archive &ar, unsigned version)
Definition: Printer.cc:890
std::string_view getName() const override
Name used to identify this pluggable.
Definition: Printer.cc:621
ImagePrinterMSX(MSXMotherBoard &motherBoard)
Definition: Printer.cc:615
virtual unsigned calcEscSequenceLength(uint8_t character)=0
void seekPrinterHeadRelative(double offset)
Definition: Printer.cc:202
void resetEmulatedPrinter()
Definition: Printer.cc:164
virtual std::pair< unsigned, unsigned > getNumberOfDots()=0
unsigned remainingCommandBytes
Definition: Printer.hh:112
std::array< uint8_t, MAX_ESC_CMDSIZE > abEscSeq
Definition: Printer.hh:132
virtual void processCharacter(uint8_t data)=0
void plot9Dots(double x, double y, unsigned pattern)
Definition: Printer.cc:173
~ImagePrinter() override
Definition: Printer.cc:119
static constexpr int MAX_ESC_CMDSIZE
Definition: Printer.hh:131
unsigned rightBorder
Definition: Printer.hh:110
unsigned sizeRemainingDataBytes
Definition: Printer.hh:114
ImagePrinter(MSXMotherBoard &motherBoard, bool graphicsHiLo)
Definition: Printer.cc:108
virtual void resetSettings()=0
void printVisibleCharacter(uint8_t data)
Definition: Printer.cc:264
void forceFormFeed() override
Definition: Printer.cc:159
static constexpr unsigned PIXEL_WIDTH
Definition: Printer.hh:94
struct openmsx::ImagePrinter::FontInfo fontInfo
virtual void processEscSequence()=0
unsigned perforationSkip
Definition: Printer.hh:108
static constexpr int MAX_FONT_WIDTH
Definition: Printer.hh:134
void flushEmulatedPrinter()
Definition: Printer.cc:233
void write(uint8_t data) override
Definition: Printer.cc:124
CountryCode countryCode
Definition: Printer.hh:129
unsigned ramLoadOffset
Definition: Printer.hh:115
void printGraphicByte(uint8_t data)
Definition: Printer.cc:182
void writeData(uint8_t data, EmuTime::param time) override
Sets the data signals.
Definition: Printer.cc:60
void setStrobe(bool strobe, EmuTime::param time) override
Sets the strobe signal: false = low, true = high.
Definition: Printer.cc:51
virtual void forceFormFeed()=0
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: Printer.cc:65
virtual void write(uint8_t data)=0
void unplugHelper(EmuTime::param time) override
Definition: Printer.cc:70
bool getStatus(EmuTime::param time) override
Returns the STATUS signal: false = low = ready, true = high = not ready.
Definition: Printer.cc:46
~PrinterCore() override=default
This file implemented 3 utility functions:
Definition: Autofire.cc:9
std::array< uint8_t, 256 *MAX_FONT_WIDTH > rom
Definition: Printer.hh:136
std::array< uint8_t, 256 *MAX_FONT_WIDTH > ram
Definition: Printer.hh:137