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 
17 namespace openmsx {
18 
19 class MSXMotherBoard;
20 class IntegerSetting;
21 class Paper;
22 
23 
24 // Abstract printer class
26 {
27 public:
28  // PrinterPortDevice
29  bool getStatus(EmuTime::param time) override;
30  void setStrobe(bool strobe, EmuTime::param time) override;
31  void writeData(byte data, EmuTime::param time) override;
32 
33  // Pluggable
34  void plugHelper(Connector& connector, EmuTime::param time) override;
35  void unplugHelper(EmuTime::param time) override;
36 
37 protected:
38  PrinterCore() = default;
39  ~PrinterCore() override = default;
40  virtual void write(byte data) = 0;
41  virtual void forceFormFeed() = 0;
42 
43 private:
44  byte toPrint = 0;
45  bool prevStrobe = true;
46 };
47 
48 /*
49 // sends data to host printer
50 class RawPrinter : public PrinterCore
51 {
52 public:
53  RawPrinter();
54  ~RawPrinter();
55 
56  void write(byte data);
57  void forceFormFeed();
58  // Pluggable
59  const std::string& getName() const override;
60  const std::string getDescription() const override;
61 
62 private:
63  HANDLE hFile;
64 };
65 */
66 
67 // Abstract image printer
68 class ImagePrinter : public PrinterCore
69 {
70 public:
71  void write(byte data) override;
72  void forceFormFeed() override;
73 
74 protected:
75  ImagePrinter(MSXMotherBoard& motherBoard, bool graphicsHiLo);
76  ~ImagePrinter() override;
77 
78  void resetEmulatedPrinter();
79  void printGraphicByte(byte data);
80  void seekPrinterHeadRelative(double offset);
81  void ensurePrintPage();
82  void flushEmulatedPrinter();
83  void printVisibleCharacter(byte data);
84  void plot9Dots(double x, double y, unsigned pattern);
85 
86  virtual void getNumberOfDots(unsigned& dotsX, unsigned& dotsY) = 0;
87  virtual void resetSettings() = 0;
88  virtual unsigned calcEscSequenceLength(byte character) = 0;
89  virtual void processEscSequence() = 0;
90  virtual void processCharacter(byte data) = 0;
91 
92  static const unsigned PIXEL_WIDTH = 8;
93 
94  double graphDensity;
95  double fontDensity;
96  double hpos;
97  double vpos;
98  double pageTop;
99  double lineFeed;
100  double pageHeight;
101  double printAreaTop;
103  double pixelSizeX;
104  double pixelSizeY;
105  int eightBit;
106  unsigned perforationSkip;
107  unsigned leftBorder;
108  unsigned rightBorder;
109  unsigned fontWidth;
111  unsigned sizeEscPos;
113  unsigned ramLoadOffset;
114  unsigned ramLoadEnd;
115  unsigned lines;
116  enum CountryCode {
117  CC_USA = 0,
118  CC_FRANCE = 1,
119  CC_GERMANY = 2,
120  CC_UNITED_KINGDOM = 3,
121  CC_DENMARK = 4,
122  CC_SWEDEN = 5,
123  CC_ITALY = 6,
124  CC_SPAIN = 7,
125  CC_JAPAN = 8
126  };
128 
129  static const int MAX_ESC_CMDSIZE = 8;
130  byte abEscSeq[MAX_ESC_CMDSIZE];
131 
132  static const int MAX_FONT_WIDTH = 12;
133  struct FontInfo {
134  byte rom[256 * MAX_FONT_WIDTH];
135  byte ram[256 * MAX_FONT_WIDTH];
136  double pixelDelta;
137  unsigned charWidth;
138  bool useRam;
139  } fontInfo;
140 
142  bool bold;
144  bool italic;
146  bool subscript;
148  bool underline;
153  bool japanese;
157  bool elite;
160 
161 private:
162  MSXMotherBoard& motherBoard;
163  std::unique_ptr<Paper> paper;
164 
165  std::shared_ptr<IntegerSetting> dpiSetting;
166 
167  const bool graphicsHiLo;
168 };
169 
170 // emulated MSX printer
171 class ImagePrinterMSX final : public ImagePrinter
172 {
173 public:
174  explicit ImagePrinterMSX(MSXMotherBoard& motherBoard);
175 
176  // Pluggable
177  const std::string& getName() const override;
178  string_view getDescription() const override;
179 
180  template<typename Archive>
181  void serialize(Archive& ar, unsigned version);
182 
183 private:
184  void msxPrnSetFont(const byte* msxBits);
185  unsigned parseNumber(unsigned sizeStart, unsigned sizeChars);
186 
187  void getNumberOfDots(unsigned& dotsX, unsigned& dotsY) override;
188  void resetSettings() override;
189  unsigned calcEscSequenceLength(byte character) override;
190  void processEscSequence() override;
191  void processCharacter(byte data) override;
192 };
193 
194 // emulated Epson printer
195 class ImagePrinterEpson final : public ImagePrinter
196 {
197 public:
198  explicit ImagePrinterEpson(MSXMotherBoard& motherBoard);
199 
200  // Pluggable
201  const std::string& getName() const override;
202  string_view getDescription() const override;
203 
204  template<typename Archive>
205  void serialize(Archive& ar, unsigned version);
206 
207 private:
208  unsigned parseNumber(unsigned sizeStart, unsigned sizeChars);
209 
210  void getNumberOfDots(unsigned& dotsX, unsigned& dotsY) override;
211  void resetSettings() override;
212  unsigned calcEscSequenceLength(byte character) override;
213  void processEscSequence() override;
214  void processCharacter(byte data) override;
215 };
216 
217 } // namespace openmsx
218 
219 #endif
virtual string_view getDescription() const =0
Description for this pluggable.
Represents something you can plug devices into.
Definition: Connector.hh:20
virtual void forceFormFeed()=0
unsigned sizeRemainingDataBytes
Definition: Printer.hh:112
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
CountryCode countryCode
Definition: Printer.hh:127
void unplugHelper(EmuTime::param time) override
Definition: Printer.cc:73
virtual void write(byte data)=0
unsigned rightBorder
Definition: Printer.hh:108
unsigned perforationSkip
Definition: Printer.hh:106
~PrinterCore() override=default
ImagePrinterEpson
Definition: Printer.cc:1646
constexpr auto data(C &c) -> decltype(c.data())
Definition: span.hh:69
ImagePrinterMSX
Definition: Printer.cc:937
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
unsigned remainingCommandBytes
Definition: Printer.hh:110
unsigned ramLoadOffset
Definition: Printer.hh:113
void writeData(byte data, EmuTime::param time) override
Sets the data signals.
Definition: Printer.cc:63
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
virtual const std::string & getName() const
Name used to identify this pluggable.
Definition: Pluggable.cc:16
void setStrobe(bool strobe, EmuTime::param time) override
Sets the strobe signal: false = low, true = high.
Definition: Printer.cc:54
bool getStatus(EmuTime::param time) override
Returns the STATUS signal: false = low = ready, true = high = not ready.
Definition: Printer.cc:49
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: Printer.cc:68
void serialize(Archive &ar, T &t, unsigned version)