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 
18 namespace openmsx {
19 
20 class MSXMotherBoard;
21 class IntegerSetting;
22 class Paper;
23 
24 
25 // Abstract printer class
27 {
28 public:
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 
38 protected:
39  PrinterCore() = default;
40  ~PrinterCore() override = default;
41  virtual void write(byte data) = 0;
42  virtual void forceFormFeed() = 0;
43 
44 private:
45  byte toPrint = 0;
46  bool prevStrobe = true;
47 };
48 
49 /*
50 // sends data to host printer
51 class RawPrinter : public PrinterCore
52 {
53 public:
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 
63 private:
64  HANDLE hFile;
65 };
66 */
67 
68 // Abstract image printer
69 class ImagePrinter : public PrinterCore
70 {
71 public:
72  void write(byte data) override;
73  void forceFormFeed() override;
74 
75 protected:
76  ImagePrinter(MSXMotherBoard& motherBoard, bool graphicsHiLo);
77  ~ImagePrinter() override;
78 
79  void resetEmulatedPrinter();
80  void printGraphicByte(byte data);
81  void seekPrinterHeadRelative(double offset);
82  void ensurePrintPage();
83  void flushEmulatedPrinter();
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 
93 protected:
94  static constexpr unsigned PIXEL_WIDTH = 8;
95 
96  double graphDensity;
97  double fontDensity;
98  double hpos;
99  double vpos;
100  double pageTop;
101  double lineFeed;
102  double pageHeight;
103  double printAreaTop;
105  double pixelSizeX;
106  double pixelSizeY;
107  int eightBit;
108  unsigned perforationSkip;
109  unsigned leftBorder;
110  unsigned rightBorder;
111  unsigned fontWidth;
113  unsigned sizeEscPos;
115  unsigned ramLoadOffset;
116  unsigned ramLoadEnd;
117  unsigned lines;
118  enum CountryCode {
119  CC_USA = 0,
125  CC_ITALY = 6,
126  CC_SPAIN = 7,
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];
138  double pixelDelta;
139  unsigned charWidth;
140  bool useRam;
142 
144  bool bold;
146  bool italic;
148  bool subscript;
150  bool underline;
155  bool japanese;
159  bool elite;
162 
163 private:
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
173 class ImagePrinterMSX final : public ImagePrinter
174 {
175 public:
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 
185 private:
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
197 class ImagePrinterEpson final : public ImagePrinter
198 {
199 public:
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 
209 private:
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:1198
void serialize(Archive &ar, unsigned version)
Definition: Printer.cc:1630
ImagePrinterEpson(MSXMotherBoard &motherBoard)
Definition: Printer.cc:1192
std::string_view getDescription() const override
Description for this pluggable.
Definition: Printer.cc:1203
std::string_view getDescription() const override
Description for this pluggable.
Definition: Printer.cc:630
void serialize(Archive &ar, unsigned version)
Definition: Printer.cc:923
std::string_view getName() const override
Name used to identify this pluggable.
Definition: Printer.cc:625
ImagePrinterMSX(MSXMotherBoard &motherBoard)
Definition: Printer.cc:618
void seekPrinterHeadRelative(double offset)
Definition: Printer.cc:234
void resetEmulatedPrinter()
Definition: Printer.cc:196
unsigned remainingCommandBytes
Definition: Printer.hh:112
void plot9Dots(double x, double y, unsigned pattern)
Definition: Printer.cc:205
~ImagePrinter() override
Definition: Printer.cc:151
void write(byte data) override
Definition: Printer.cc:156
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:191
static constexpr unsigned PIXEL_WIDTH
Definition: Printer.hh:94
void printVisibleCharacter(byte data)
Definition: Printer.cc:296
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:214
unsigned perforationSkip
Definition: Printer.hh:108
static constexpr int MAX_FONT_WIDTH
Definition: Printer.hh:134
void flushEmulatedPrinter()
Definition: Printer.cc:265
virtual std::pair< unsigned, unsigned > getNumberOfDots()=0
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:118
byte ram[256 *MAX_FONT_WIDTH]
Definition: Printer.hh:137
byte rom[256 *MAX_FONT_WIDTH]
Definition: Printer.hh:136