OXYGENHUB
◆ main openmsx / src / Printer.hh
4.4 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
/** \file Printer.hh
2
 * Dot Matrix Printer Emulation
3
 *   code mostly copied from blueMSX
4
 *   but changed to:
5
 *      OO-style
6
 *      save to png images (with anti-aliased circles)
7
 *      fit in openMSX structure
8
 */
9
10
#ifndef PRINTER_HH
11
#define PRINTER_HH
12
13
#include "PrinterCore.hh"
14
15
#include <array>
16
#include <memory>
17
#include <utility>
18
19
namespace openmsx {
20
21
class MSXMotherBoard;
22
class IntegerSetting;
23
class Paper;
24
25
// Abstract image printer
26
class ImagePrinter : public PrinterCore
27
{
28
public:
29
	void write(uint8_t data) override;
30
	void forceFormFeed() override;
31
32
protected:
33
	ImagePrinter(MSXMotherBoard& motherBoard, bool graphicsHiLo);
34
	~ImagePrinter() override;
35
36
	void resetEmulatedPrinter();
37
	void printGraphicByte(uint8_t data);
38
	void seekPrinterHeadRelative(double offset);
39
	void ensurePrintPage();
40
	void flushEmulatedPrinter();
41
	void printVisibleCharacter(uint8_t data);
42
	void plot9Dots(double x, double y, unsigned pattern);
43
44
	[[nodiscard]] virtual std::pair<unsigned, unsigned> getNumberOfDots() = 0;
45
	virtual void resetSettings() = 0;
46
	[[nodiscard]] virtual unsigned calcEscSequenceLength(uint8_t character) = 0;
47
	virtual void processEscSequence() = 0;
48
	virtual void processCharacter(uint8_t data) = 0;
49
50
protected:
51
	static constexpr unsigned PIXEL_WIDTH = 8;
52
53
	double graphDensity;
54
	double fontDensity;
55
	double hpos;
56
	double vpos;
57
	double pageTop;
58
	double lineFeed;
59
	double pageHeight;
60
	double printAreaTop = -1.0;
61
	double printAreaBottom = 0.0;
62
	double pixelSizeX;
63
	double pixelSizeY;
64
	int  eightBit = 0;
65
	unsigned perforationSkip = 0;
66
	unsigned leftBorder;
67
	unsigned rightBorder;
68
	unsigned fontWidth;
69
	unsigned remainingCommandBytes = 0;
70
	unsigned sizeEscPos = 0;
71
	unsigned sizeRemainingDataBytes = 0;
72
	unsigned ramLoadOffset = 0;
73
	unsigned ramLoadEnd = 0;
74
	unsigned lines;
75
	enum class CountryCode : uint8_t {
76
		USA              = 0,
77
		FRANCE           = 1,
78
		GERMANY          = 2,
79
		UNITED_KINGDOM   = 3,
80
		DENMARK          = 4,
81
		SWEDEN           = 5,
82
		ITALY            = 6,
83
		SPAIN            = 7,
84
		JAPAN            = 8
85
	};
86
	CountryCode countryCode = CountryCode::USA;
87
88
	static constexpr int MAX_ESC_CMDSIZE = 8;
89
	std::array<uint8_t, MAX_ESC_CMDSIZE> abEscSeq;
90
91
	static constexpr int MAX_FONT_WIDTH = 12;
92
	struct FontInfo {
93
		std::array<uint8_t, 256 * MAX_FONT_WIDTH> rom;
94
		std::array<uint8_t, 256 * MAX_FONT_WIDTH> ram;
95
		double pixelDelta;
96
		unsigned charWidth;
97
		bool useRam;
98
	} fontInfo;
99
100
	bool letterQuality = false;
101
	bool bold = false;
102
	bool proportional = false;
103
	bool italic = false;
104
	bool superscript = false;
105
	bool subscript = false;
106
	bool doubleWidth = false;
107
	bool underline = false;
108
	bool doubleStrike = false;
109
	bool escSequence = false;
110
	bool alternateChar = false;
111
	bool detectPaperOut = false;
112
	bool japanese = false;
113
	bool normalAfterLine = false;
114
	bool ninePinGraphics = false;
115
	bool leftToRight = false;
116
	bool elite = false;
117
	bool compressed = false;
118
	bool noHighEscapeCodes = false;
119
120
private:
121
	MSXMotherBoard& motherBoard;
122
	std::unique_ptr<Paper> paper;
123
124
	std::shared_ptr<IntegerSetting> dpiSetting;
125
126
	const bool graphicsHiLo;
127
};
128
129
// emulated MSX printer
130
class ImagePrinterMSX final : public ImagePrinter
131
{
132
public:
133
	explicit ImagePrinterMSX(MSXMotherBoard& motherBoard);
134
135
	// Pluggable
136
	[[nodiscard]] zstring_view getName() const override;
137
	[[nodiscard]] zstring_view getDescription() const override;
138
139
	template<typename Archive>
140
	void serialize(Archive& ar, unsigned version);
141
142
private:
143
	[[nodiscard]] unsigned parseNumber(unsigned sizeStart, unsigned sizeChars);
144
145
	[[nodiscard]] std::pair<unsigned, unsigned> getNumberOfDots() override;
146
	void resetSettings() override;
147
	[[nodiscard]] unsigned calcEscSequenceLength(uint8_t character) override;
148
	void processEscSequence() override;
149
	void processCharacter(uint8_t data) override;
150
};
151
152
// emulated Epson printer
153
class ImagePrinterEpson final : public ImagePrinter
154
{
155
public:
156
	explicit ImagePrinterEpson(MSXMotherBoard& motherBoard);
157
158
	// Pluggable
159
	[[nodiscard]] zstring_view getName() const override;
160
	[[nodiscard]] zstring_view getDescription() const override;
161
162
	template<typename Archive>
163
	void serialize(Archive& ar, unsigned version);
164
165
private:
166
	[[nodiscard]] unsigned parseNumber(unsigned sizeStart, unsigned sizeChars);
167
168
	[[nodiscard]] std::pair<unsigned, unsigned> getNumberOfDots() override;
169
	void resetSettings() override;
170
	[[nodiscard]] unsigned calcEscSequenceLength(uint8_t character) override;
171
	void processEscSequence() override;
172
	void processCharacter(uint8_t data) override;
173
};
174
175
} // namespace openmsx
176
177
#endif