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 "openmsx.hh"
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(byte 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(byte data) = 0;
42 virtual void forceFormFeed() = 0;
43
44private:
45 byte 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(byte 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(byte data) override;
73 void forceFormFeed() override;
74
75protected:
76 ImagePrinter(MSXMotherBoard& motherBoard, bool graphicsHiLo);
77 ~ImagePrinter() override;
78
80 void printGraphicByte(byte data);
81 void seekPrinterHeadRelative(double offset);
82 void ensurePrintPage();
84 void printVisibleCharacter(byte 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(byte character) = 0;
90 virtual void processEscSequence() = 0;
91 virtual void processCharacter(byte 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;
133
134 static constexpr int MAX_FONT_WIDTH = 12;
135 struct FontInfo {
136 byte rom[256 * MAX_FONT_WIDTH];
137 byte ram[256 * MAX_FONT_WIDTH];
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 void msxPrnSetFont(const byte* msxBits);
187 [[nodiscard]] unsigned parseNumber(unsigned sizeStart, unsigned sizeChars);
188
189 [[nodiscard]] std::pair<unsigned, unsigned> getNumberOfDots() override;
190 void resetSettings() override;
191 [[nodiscard]] unsigned calcEscSequenceLength(byte character) override;
192 void processEscSequence() override;
193 void processCharacter(byte data) override;
194};
195
196// emulated Epson printer
197class ImagePrinterEpson final : public ImagePrinter
198{
199public:
200 explicit ImagePrinterEpson(MSXMotherBoard& motherBoard);
201
202 // Pluggable
203 [[nodiscard]] std::string_view getName() const override;
204 [[nodiscard]] std::string_view getDescription() const override;
205
206 template<typename Archive>
207 void serialize(Archive& ar, unsigned version);
208
209private:
210 [[nodiscard]] unsigned parseNumber(unsigned sizeStart, unsigned sizeChars);
211
212 [[nodiscard]] std::pair<unsigned, unsigned> getNumberOfDots() override;
213 void resetSettings() override;
214 [[nodiscard]] unsigned calcEscSequenceLength(byte character) override;
215 void processEscSequence() override;
216 void processCharacter(byte data) override;
217};
218
219} // namespace openmsx
220
221#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:1167
void serialize(Archive &ar, unsigned version)
Definition: Printer.cc:1599
ImagePrinterEpson(MSXMotherBoard &motherBoard)
Definition: Printer.cc:1161
std::string_view getDescription() const override
Description for this pluggable.
Definition: Printer.cc:1172
std::string_view getDescription() const override
Description for this pluggable.
Definition: Printer.cc:599
void serialize(Archive &ar, unsigned version)
Definition: Printer.cc:892
std::string_view getName() const override
Name used to identify this pluggable.
Definition: Printer.cc:594
ImagePrinterMSX(MSXMotherBoard &motherBoard)
Definition: Printer.cc:587
void seekPrinterHeadRelative(double offset)
Definition: Printer.cc:203
void resetEmulatedPrinter()
Definition: Printer.cc:165
virtual std::pair< unsigned, unsigned > getNumberOfDots()=0
unsigned remainingCommandBytes
Definition: Printer.hh:112
void plot9Dots(double x, double y, unsigned pattern)
Definition: Printer.cc:174
~ImagePrinter() override
Definition: Printer.cc:120
void write(byte data) override
Definition: Printer.cc:125
static constexpr int MAX_ESC_CMDSIZE
Definition: Printer.hh:131
unsigned rightBorder
Definition: Printer.hh:110
unsigned sizeRemainingDataBytes
Definition: Printer.hh:114
virtual void processCharacter(byte data)=0
ImagePrinter(MSXMotherBoard &motherBoard, bool graphicsHiLo)
Definition: Printer.cc:109
virtual void resetSettings()=0
void forceFormFeed() override
Definition: Printer.cc:160
static constexpr unsigned PIXEL_WIDTH
Definition: Printer.hh:94
void printVisibleCharacter(byte data)
Definition: Printer.cc:265
struct openmsx::ImagePrinter::FontInfo fontInfo
byte abEscSeq[MAX_ESC_CMDSIZE]
Definition: Printer.hh:132
virtual void processEscSequence()=0
void printGraphicByte(byte data)
Definition: Printer.cc:183
unsigned perforationSkip
Definition: Printer.hh:108
static constexpr int MAX_FONT_WIDTH
Definition: Printer.hh:134
void flushEmulatedPrinter()
Definition: Printer.cc:234
virtual unsigned calcEscSequenceLength(byte character)=0
CountryCode countryCode
Definition: Printer.hh:129
unsigned ramLoadOffset
Definition: Printer.hh:115
virtual void write(byte data)=0
void setStrobe(bool strobe, EmuTime::param time) override
Sets the strobe signal: false = low, true = high.
Definition: Printer.cc:52
virtual void forceFormFeed()=0
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: Printer.cc:66
void writeData(byte data, EmuTime::param time) override
Sets the data signals.
Definition: Printer.cc:61
void unplugHelper(EmuTime::param time) override
Definition: Printer.cc:71
bool getStatus(EmuTime::param time) override
Returns the STATUS signal: false = low = ready, true = high = not ready.
Definition: Printer.cc:47
~PrinterCore() override=default
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr KeyMatrixPosition x
Keyboard bindings.
Definition: Keyboard.cc:127
byte ram[256 *MAX_FONT_WIDTH]
Definition: Printer.hh:137
byte rom[256 *MAX_FONT_WIDTH]
Definition: Printer.hh:136