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 constexpr 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,
123  CC_ITALY = 6,
124  CC_SPAIN = 7,
126  };
128 
129  static constexpr int MAX_ESC_CMDSIZE = 8;
131 
132  static constexpr 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  std::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  std::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
openmsx.hh
openmsx::ImagePrinter::fontDensity
double fontDensity
Definition: Printer.hh:95
openmsx::ImagePrinterEpson
Definition: Printer.hh:195
openmsx::ImagePrinter::proportional
bool proportional
Definition: Printer.hh:143
openmsx::ImagePrinterEpson::getDescription
std::string_view getDescription() const override
Description for this pluggable.
Definition: Printer.cc:1214
openmsx::ImagePrinter::printAreaBottom
double printAreaBottom
Definition: Printer.hh:102
openmsx::ImagePrinter::resetSettings
virtual void resetSettings()=0
openmsx::PrinterCore::~PrinterCore
~PrinterCore() override=default
openmsx::ImagePrinter::FontInfo::rom
byte rom[256 *MAX_FONT_WIDTH]
Definition: Printer.hh:134
openmsx::ImagePrinter::CC_DENMARK
Definition: Printer.hh:121
openmsx::ImagePrinter::write
void write(byte data) override
Definition: Printer.cc:158
openmsx::ImagePrinter::italic
bool italic
Definition: Printer.hh:144
openmsx::ImagePrinter
Definition: Printer.hh:68
openmsx::ImagePrinter::FontInfo
Definition: Printer.hh:133
openmsx::ImagePrinter::FontInfo::pixelDelta
double pixelDelta
Definition: Printer.hh:136
openmsx::PrinterCore::PrinterCore
PrinterCore()=default
openmsx::PrinterCore::setStrobe
void setStrobe(bool strobe, EmuTime::param time) override
Sets the strobe signal: false = low, true = high.
Definition: Printer.cc:54
openmsx::PrinterCore::writeData
void writeData(byte data, EmuTime::param time) override
Sets the data signals.
Definition: Printer.cc:63
openmsx::ImagePrinterEpson::ImagePrinterEpson
ImagePrinterEpson(MSXMotherBoard &motherBoard)
Definition: Printer.cc:1202
openmsx::ImagePrinter::plot9Dots
void plot9Dots(double x, double y, unsigned pattern)
Definition: Printer.cc:207
openmsx::ImagePrinter::CC_SPAIN
Definition: Printer.hh:124
openmsx::ImagePrinterMSX::ImagePrinterMSX
ImagePrinterMSX(MSXMotherBoard &motherBoard)
Definition: Printer.cc:621
openmsx::ImagePrinter::pixelSizeY
double pixelSizeY
Definition: Printer.hh:104
openmsx::ImagePrinter::CC_SWEDEN
Definition: Printer.hh:122
PrinterPortDevice.hh
openmsx::ImagePrinter::ninePinGraphics
bool ninePinGraphics
Definition: Printer.hh:155
openmsx::ImagePrinter::underline
bool underline
Definition: Printer.hh:148
openmsx::ImagePrinter::noHighEscapeCodes
bool noHighEscapeCodes
Definition: Printer.hh:159
openmsx::ImagePrinter::resetEmulatedPrinter
void resetEmulatedPrinter()
Definition: Printer.cc:198
openmsx::ImagePrinter::compressed
bool compressed
Definition: Printer.hh:158
openmsx::ImagePrinter::ensurePrintPage
void ensurePrintPage()
Definition: Printer.cc:249
openmsx::ImagePrinter::detectPaperOut
bool detectPaperOut
Definition: Printer.hh:152
openmsx::ImagePrinterEpson::getName
const std::string & getName() const override
Name used to identify this pluggable.
Definition: Printer.cc:1208
openmsx::ImagePrinter::FontInfo::useRam
bool useRam
Definition: Printer.hh:138
openmsx::ImagePrinter::MAX_ESC_CMDSIZE
static constexpr int MAX_ESC_CMDSIZE
Definition: Printer.hh:129
openmsx::ImagePrinter::remainingCommandBytes
unsigned remainingCommandBytes
Definition: Printer.hh:110
openmsx::ImagePrinter::normalAfterLine
bool normalAfterLine
Definition: Printer.hh:154
openmsx::ImagePrinter::sizeEscPos
unsigned sizeEscPos
Definition: Printer.hh:111
openmsx::PrinterCore::getStatus
bool getStatus(EmuTime::param time) override
Returns the STATUS signal: false = low = ready, true = high = not ready.
Definition: Printer.cc:49
openmsx::ImagePrinter::seekPrinterHeadRelative
void seekPrinterHeadRelative(double offset)
Definition: Printer.cc:236
openmsx::ImagePrinter::CC_ITALY
Definition: Printer.hh:123
openmsx::ImagePrinter::graphDensity
double graphDensity
Definition: Printer.hh:94
openmsx::PrinterCore
Definition: Printer.hh:25
openmsx::ImagePrinter::ramLoadEnd
unsigned ramLoadEnd
Definition: Printer.hh:114
openmsx::ImagePrinter::getNumberOfDots
virtual void getNumberOfDots(unsigned &dotsX, unsigned &dotsY)=0
openmsx::ImagePrinter::CountryCode
CountryCode
Definition: Printer.hh:116
openmsx::ImagePrinter::ImagePrinter
ImagePrinter(MSXMotherBoard &motherBoard, bool graphicsHiLo)
Definition: Printer.cc:111
openmsx::ImagePrinter::vpos
double vpos
Definition: Printer.hh:97
openmsx::ImagePrinter::elite
bool elite
Definition: Printer.hh:157
openmsx::ImagePrinter::CC_GERMANY
Definition: Printer.hh:119
openmsx::ImagePrinter::letterQuality
bool letterQuality
Definition: Printer.hh:141
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:59
openmsx::ImagePrinter::FontInfo::charWidth
unsigned charWidth
Definition: Printer.hh:137
openmsx::PrinterCore::plugHelper
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: Printer.cc:68
openmsx::ImagePrinter::ramLoadOffset
unsigned ramLoadOffset
Definition: Printer.hh:113
openmsx::ImagePrinter::superscript
bool superscript
Definition: Printer.hh:145
openmsx::ImagePrinter::lineFeed
double lineFeed
Definition: Printer.hh:99
openmsx::PrinterCore::forceFormFeed
virtual void forceFormFeed()=0
openmsx::ImagePrinter::lines
unsigned lines
Definition: Printer.hh:115
openmsx::ImagePrinterMSX::getDescription
std::string_view getDescription() const override
Description for this pluggable.
Definition: Printer.cc:634
openmsx::ImagePrinter::hpos
double hpos
Definition: Printer.hh:96
openmsx::ImagePrinter::printAreaTop
double printAreaTop
Definition: Printer.hh:101
openmsx::ImagePrinter::countryCode
CountryCode countryCode
Definition: Printer.hh:127
openmsx::ImagePrinter::abEscSeq
byte abEscSeq[MAX_ESC_CMDSIZE]
Definition: Printer.hh:130
openmsx::ImagePrinter::japanese
bool japanese
Definition: Printer.hh:153
openmsx::ImagePrinter::FontInfo::ram
byte ram[256 *MAX_FONT_WIDTH]
Definition: Printer.hh:135
openmsx::ImagePrinter::fontWidth
unsigned fontWidth
Definition: Printer.hh:109
openmsx::ImagePrinter::alternateChar
bool alternateChar
Definition: Printer.hh:151
openmsx::ImagePrinter::processEscSequence
virtual void processEscSequence()=0
openmsx::ImagePrinter::sizeRemainingDataBytes
unsigned sizeRemainingDataBytes
Definition: Printer.hh:112
openmsx::ImagePrinter::bold
bool bold
Definition: Printer.hh:142
openmsx::ImagePrinter::calcEscSequenceLength
virtual unsigned calcEscSequenceLength(byte character)=0
openmsx::ImagePrinter::printGraphicByte
void printGraphicByte(byte data)
Definition: Printer.cc:216
openmsx::x
constexpr KeyMatrixPosition x
Keyboard bindings.
Definition: Keyboard.cc:1377
openmsx::ImagePrinter::CC_JAPAN
Definition: Printer.hh:125
openmsx::ImagePrinter::doubleWidth
bool doubleWidth
Definition: Printer.hh:147
openmsx::ImagePrinter::doubleStrike
bool doubleStrike
Definition: Printer.hh:149
openmsx::ImagePrinter::flushEmulatedPrinter
void flushEmulatedPrinter()
Definition: Printer.cc:268
openmsx::ImagePrinter::forceFormFeed
void forceFormFeed() override
Definition: Printer.cc:193
openmsx::ImagePrinter::processCharacter
virtual void processCharacter(byte data)=0
openmsx::ImagePrinterMSX::serialize
void serialize(Archive &ar, unsigned version)
Definition: Printer.cc:933
openmsx::ImagePrinterMSX::getName
const std::string & getName() const override
Name used to identify this pluggable.
Definition: Printer.cc:628
openmsx::ImagePrinter::~ImagePrinter
~ImagePrinter() override
Definition: Printer.cc:153
openmsx::Connector
Represents something you can plug devices into.
Definition: Connector.hh:20
openmsx::ImagePrinter::pageHeight
double pageHeight
Definition: Printer.hh:100
openmsx::PrinterCore::write
virtual void write(byte data)=0
openmsx::ImagePrinter::MAX_FONT_WIDTH
static constexpr int MAX_FONT_WIDTH
Definition: Printer.hh:132
openmsx::ImagePrinter::eightBit
int eightBit
Definition: Printer.hh:105
openmsx::ImagePrinter::printVisibleCharacter
void printVisibleCharacter(byte data)
Definition: Printer.cc:299
openmsx::ImagePrinter::escSequence
bool escSequence
Definition: Printer.hh:150
openmsx::ImagePrinter::PIXEL_WIDTH
static constexpr unsigned PIXEL_WIDTH
Definition: Printer.hh:92
openmsx::ImagePrinter::subscript
bool subscript
Definition: Printer.hh:146
openmsx::ImagePrinterEpson::serialize
void serialize(Archive &ar, unsigned version)
Definition: Printer.cc:1642
openmsx::ImagePrinter::fontInfo
struct openmsx::ImagePrinter::FontInfo fontInfo
openmsx::ImagePrinter::CC_USA
Definition: Printer.hh:117
openmsx::ImagePrinter::pageTop
double pageTop
Definition: Printer.hh:98
openmsx::ImagePrinter::pixelSizeX
double pixelSizeX
Definition: Printer.hh:103
openmsx::ImagePrinter::CC_FRANCE
Definition: Printer.hh:118
openmsx::PrinterPortDevice
Definition: PrinterPortDevice.hh:9
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::PrinterCore::unplugHelper
void unplugHelper(EmuTime::param time) override
Definition: Printer.cc:73
openmsx::ImagePrinter::rightBorder
unsigned rightBorder
Definition: Printer.hh:108
openmsx::ImagePrinterMSX
Definition: Printer.hh:171
openmsx::ImagePrinter::CC_UNITED_KINGDOM
Definition: Printer.hh:120
openmsx::ImagePrinter::leftBorder
unsigned leftBorder
Definition: Printer.hh:107
openmsx::ImagePrinter::perforationSkip
unsigned perforationSkip
Definition: Printer.hh:106
openmsx::ImagePrinter::leftToRight
bool leftToRight
Definition: Printer.hh:156