ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
screen_eob.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef KYRA_SCREEN_EOB_H
23 #define KYRA_SCREEN_EOB_H
24 
25 #ifdef ENABLE_EOB
26 
27 #include "graphics/big5.h"
28 
29 #include "kyra/graphics/screen.h"
30 
31 namespace Kyra {
32 
33 class EoBCoreEngine;
34 class SegaRenderer;
35 class SegaAnimator;
36 class Screen_EoB : public Screen {
37 friend class SegaRenderer;
38 public:
39  // The purpose of this enum is to keep better track of which page is used
40  // when and for which purpose. We use the pages for more backup operations
41  // than the original and also have to deal with the different ports which
42  // all do their own things. This is supposed to help avoid using pages that
43  // are already in use for something else. It also allows for quick fixes
44  // if necessary.
45  enum {
46  kSegaInitShapesPage = 7,
47  kSegaRenderPage = 8,
48  kDefeatMsgBackupPage = 10,
49  kCheckPwBackupPage = 10,
50  kSpellbookBackupPage = 10,
51  kEoB2ScriptHelperPage = 12,
52  kCampMenuBackupPage = 12
53  };
54 
55 public:
56  Screen_EoB(EoBCoreEngine *vm, OSystem *system);
57  ~Screen_EoB() override;
58 
59  bool init() override;
60 
61  void setClearScreenDim(int dim);
62  void clearCurDim();
63  void clearCurDimOvl(int pageNum);
64 
65  void setMouseCursor(int x, int y, const byte *shape) override;
66  void setMouseCursor(int x, int y, const byte *shape, const uint8 *ovl);
67 
68  void loadFileDataToPage(Common::SeekableReadStream *s, int pageNum, uint32 size);
69 
70  void printShadedText(const char *string, int x, int y, int col1, int col2, int shadowCol, int pitch = -1);
71 
72  static void eob2ChineseLZUncompress(byte *dest, uint32 destSize, Common::SeekableReadStream *src);
73  void loadChineseEOB2LZBitmap(Common::SeekableReadStream *s, int pageNum, uint32 size);
74  void loadBitmap(const char *filename, int tempPage, int dstPage, Palette *pal, bool skip = false) override;
75  void loadEoBBitmap(const char *file, const uint8 *cgaMapping, int tempPage, int destPage, int convertToPage);
76  void loadShapeSetBitmap(const char *file, int tempPage, int destPage);
77 
78  void convertPage(int srcPage, int dstPage, const uint8 *cgaMapping);
79 
80  void setScreenPalette(const Palette &pal) override;
81  void getRealPalette(int num, uint8 *dst) override;
82 
83  uint8 *encodeShape(uint16 x, uint16 y, uint16 w, uint16 h, bool encode8bit = false, const uint8 *cgaMapping = 0);
84  void drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int sd = -1, int flags = 0, ...) override;
85  void drawT1Shape(uint8 pageNum, const byte *t1data, int x, int y, int sd);
86  const uint8 *scaleShape(const uint8 *shapeData, int blockDistance);
87  const uint8 *scaleShapeStep(const uint8 *shp);
88  const uint8 *generateShapeOverlay(const uint8 *shp, const uint8 *fadingTable);
89 
90  void setShapeFrame(int x1, int y1, int x2, int y2);
91  void enableShapeBackgroundFading(bool enable);
92  void setShapeFadingLevel(int val);
93 
94  void setGfxParameters(int x, int y, int col);
95  void drawExplosion(int scale, int radius, int numElements, int stepSize, int aspectRatio, const uint8 *colorTable, int colorTableSize);
96  void drawVortex(int numElements, int radius, int stepSize, int, int disorder, const uint8 *colorTable, int colorTableSize);
97 
98  void fadeTextColor(Palette *pal, int color, int rate);
99  bool delayedFadePalStep(Palette *fadePal, Palette *destPal, int rate);
100 
101  void setTextColorMap(const uint8 *cmap) override {}
102  int getRectSize(int w, int h) override;
103 
104  void setFadeTable(const uint8 *table);
105  void createFadeTable(const uint8 *palData, uint8 *dst, uint8 rootColor, uint8 weight);
106  void createFadeTable16bit(const uint16 *palData, uint16 *dst, uint16 rootColor, uint8 weight);
107 
108  const uint16 *getCGADitheringTable(int index);
109  const uint8 *getEGADitheringTable();
110 
111  bool loadFont(FontId fontId, const char *filename) override;
112 
113  // FM-Towns specific
114  void decodeSHP(const uint8 *data, int dstPage);
115  void convertToHiColor(int page);
116  void shadeRect(int x1, int y1, int x2, int y2, int shadingLevel);
117 
118  // PC-98 specific
119  void selectPC98Palette(int palID, Palette &dest, int brightness = 0, bool set = false);
120  void decodeBIN(const uint8 *src, uint8 *dst, uint16 inSize);
121  void decodePC98PlanarBitmap(uint8 *srcDstBuffer, uint8 *tmpBuffer, uint16 size = 64000);
122 
123  struct PalCycleData {
124  const int8 *data;
125  uint8 delay;
126  };
127 
128  void initPC98PaletteCycle(int palID, PalCycleData *data);
129  void updatePC98PaletteCycle(int brightness);
130 
131  PalCycleData *_activePalCycle;
132  uint8 *_cyclePalette;
133 
134  // Amiga specific
135  void loadSpecialAmigaCPS(const char *fileName, int destPage, bool isGraphics);
136  // This is a simple way of emulating the Amiga copper list palette magic for more than 32 colors.
137  // I use colors 32 to 63 for these extra colors (which the Amiga copper sends to the color
138  // registers on the fly at vertical beam position 120).
139  void setDualPalettes(Palette &top, Palette &bottom);
140 
141  // SegaCD specific
142  void sega_initGraphics();
143  void sega_selectPalette(int srcPalID, int dstPalID, bool set = false);
144  void sega_loadCustomPaletteData(Common::ReadStream *in);
145  void sega_updatePaletteFaders(int palID);
146  void sega_fadePalette(int delay, int16 brEnd, int dstPalID = -1, bool waitForCompletion = true, bool noUpdate = false);
147  void sega_fadeToBlack(int delay) { sega_fadePalette(delay, -7); }
148  void sega_fadeToWhite(int delay) { sega_fadePalette(delay, 7); }
149  void sega_fadeToNeutral(int delay) { sega_fadePalette(delay, 0); }
150  void sega_paletteOps(int16 opPal, int16 par1, int16 par2);
151  void sega_setTextBuffer(uint8 *buffer, uint32 bufferSize);
152  void sega_clearTextBuffer(uint8 col);
153  void sega_loadTextBackground(const uint8 *src, uint16 size);
154  void sega_drawTextBox(int pW, int pH, int x, int y, int w, int h, uint8 color1, uint8 color2);
155  void sega_loadTextBufferToVRAM(uint16 srcOffset, uint16 addr, int size);
156  void sega_gfxScale(uint8 *out, uint16 w, uint16 h, uint16 pitch, const uint8 *in, const uint16 *stampMap, const uint16 *traceVectors);
157  void sega_drawClippedLine(int pW, int pH, int x, int y, int w, int h, uint8 color);
158  uint8 *sega_convertShape(const uint8 *src, int w, int h, int pal, int hOffs = 0);
159  void sega_encodeShapesFromSprites(const uint8 **dst, const uint8 *src, int numShapes, int w, int h, int pal, bool removeSprites = true);
160 
161  SegaRenderer *sega_getRenderer() const { return _segaRenderer; }
162  SegaAnimator *sega_getAnimator() const { return _segaAnimator; }
163 
164 private:
165  void updateDirtyRects() override;
166  void ditherRect(const uint8 *src, uint8 *dst, int dstPitch, int srcW, int srcH, int colorKey = -1);
167 
168  void drawShapeSetPixel(uint8 *dst, uint8 col);
169  void scaleShapeProcessLine2Bit(uint8 *&shpDst, const uint8 *&shpSrc, uint32 transOffsetDst, uint32 transOffsetSrc);
170  void scaleShapeProcessLine4Bit(uint8 *&dst, const uint8 *&src);
171  bool posWithinRect(int posX, int posY, int x1, int y1, int x2, int y2);
172 
173  void setPagePixel16bit(int pageNum, int x, int y, uint16 color);
174 
175  void generateEGADitheringTable(const Palette &pal);
176  void generateCGADitheringTables(const uint8 *mappingData);
177 
178  int _dsDiv, _dsRem, _dsScaleTrans;
179  uint8 *_cgaScaleTable;
180  int16 _gfxX, _gfxY;
181  uint16 _gfxCol;
182  const uint8 *_gfxMaxY;
183 
184  int16 _dsX1, _dsX2, _dsY1, _dsY2;
185 
186  bool _dsBackgroundFading;
187  int16 _dsBackgroundFadingXOffs;
188  uint8 _shapeOverlay[16];
189 
190  uint8 *_dsTempPage;
191  uint8 *_shpBuffer;
192  uint8 *_convertHiColorBuffer;
193 
194  uint16 *_cgaDitheringTables[2];
195  const uint8 *_cgaMappingDefault;
196 
197  uint8 *_egaDitheringTable;
198  uint8 *_egaDitheringTempPage;
199 
200  Common::String _cpsFilePattern;
201 
202  const uint16 _cursorColorKey16Bit;
203 
204  static const uint8 _egaMatchTable[];
205  static const ScreenDim _screenDimTableIntl[];
206  static const ScreenDim _screenDimTableZH[];
207  static const int _screenDimTableCount;
208 
209  // SegaCD specific
210  struct PaletteFader {
211  PaletteFader() : _brCur(0), _brDest(0), _fadeIncr(0), _fadeDelay(0), _fadeTimer(0), _needRefresh(false) {}
212  int16 _brCur;
213  int16 _brDest;
214  int16 _fadeIncr;
215  int16 _fadeDelay;
216  int16 _fadeTimer;
217  bool _needRefresh;
218  };
219 
220  PaletteFader *_palFaders;
221  bool _specialColorReplace;
222  SegaRenderer *_segaRenderer;
223  SegaAnimator *_segaAnimator;
224  uint16 _segaCurPalette[64];
225  uint16 *_segaCustomPalettes;
226  uint8 *_defaultRenderBuffer;
227  int _defaultRenderBufferSize;
228 
230 };
231 
232 class ChineseTwoByteFontEoB final : public Font {
233 public:
234  ChineseTwoByteFontEoB(Common::SharedPtr<Graphics::Big5Font> big5, Font *singleByte) : _big5(big5), _singleByte(singleByte), _border(false), _colorMap(nullptr) {}
235 
236  virtual Type getType() const override { return kBIG5; }
237 
238  bool load(Common::SeekableReadStream &data) override {
239  return _singleByte->load(data);
240  }
241 
242  void setStyles(int styles) override { _border = (styles & kStyleBorder); _singleByte->setStyles(styles); }
243  int getHeight() const override { return MAX(_big5->getFontHeight(), _singleByte->getHeight()); }
244  int getWidth() const override { return MAX(_big5->kChineseTraditionalWidth + 2, _singleByte->getWidth()); }
245  void setColorMap(const uint8 *src) override { _colorMap = src; _singleByte->setColorMap(src); }
246  int getCharWidth(uint16 c) const override;
247  int getCharHeight(uint16 c) const override;
248  void drawChar(uint16 c, byte *dst, int pitch, int bpp) const override;
249 
250 private:
251  uint16 translateBig5(uint16 in) const;
253  Common::ScopedPtr<Font> _singleByte;
254  bool _border;
255  const uint8 *_colorMap;
256 };
257 
263 class OldDOSFont : public Font {
264 public:
265  OldDOSFont(Common::RenderMode mode, uint8 shadowColor, bool remapCharacters = true);
266  ~OldDOSFont() override;
267 
268  bool load(Common::SeekableReadStream &file) override;
269  bool loadPCBIOSTall();
270  Type getType() const override { return kASCII; }
271  int getHeight() const override { return _height; }
272  int getWidth() const override { return _width; }
273  bool usesOverlay() const override { return _useOverlay; }
274  int getCharWidth(uint16 c) const override;
275  void setColorMap(const uint8 *src) override;
276  void set16bitColorMap(const uint16 *src) override { _colorMap16bit = src; }
277  void setStyles(int styles) override { _style = styles; }
278  void drawChar(uint16 c, byte *dst, int pitch, int bpp) const override;
279 
280 protected:
281  void unload();
282 
283  int _style;
284  const uint8 *_colorMap8bit;
285  uint8 *_data;
286  uint16 *_bitmapOffsets;
287  int _width, _height;
288  int _numGlyphs;
289  uint8 _shadowColor;
290 
291  uint16 _numGlyphsMax;
292  bool _useOverlay;
293  int _scaleV;
294 
295 private:
296  void drawCharIntern(uint16 c, byte *dst, int pitch, int bpp, int col1, int col2) const;
297  virtual uint16 convert(uint16 c) const;
298  Common::RenderMode _renderMode;
299  const uint16 *_colorMap16bit;
300  bool _remapCharacters;
301 
302  static uint16 *_cgaDitheringTable;
303  static int _numRef;
304 };
305 
309 class Resource;
310 class AmigaDOSFont : public Font {
311 public:
312  AmigaDOSFont(Resource *res, bool needsLocalizedFont = false);
313  ~AmigaDOSFont() override { unload(); }
314 
315  bool load(Common::SeekableReadStream &file) override;
316  Type getType() const override { return kASCII; }
317  int getHeight() const override { return _height; }
318  int getWidth() const override { return _width; }
319  int getCharWidth(uint16 c) const override;
320  void setColorMap(const uint8 *src) override { _colorMap = src; }
321  void drawChar(uint16 c, byte *dst, int pitch, int) const override;
322 
323  static void errorDialog(int index);
324 
325 private:
326  void unload();
327 
328  struct TextFont {
329  TextFont() : data(0), bitmap(0), location(0), spacing(0), kerning(0), height(0), width(0), baseLine(0), firstChar(0), lastChar(0), modulo(0) {}
330  ~TextFont() {
331  delete[] data;
332  }
333 
334  uint16 height;
335  uint16 width;
336  uint16 baseLine;
337  uint8 firstChar;
338  uint8 lastChar;
339  uint16 modulo;
340  const uint8 *data;
341  const uint8 *bitmap;
342  const uint16 *location;
343  const int16 *spacing;
344  const int16 *kerning;
345  };
346 
347  TextFont *loadContentFile(const Common::Path &fileName);
348  void selectMode(int mode);
349 
350  struct FontContent {
351  FontContent() : height(0), style(0), flags(0) {}
352  ~FontContent() {
353  data.reset();
354  }
355 
356  Common::String contentFile;
358  uint16 height;
359  uint8 style;
360  uint8 flags;
361  };
362 
363  int _width, _height;
364  uint8 _first, _last;
365  FontContent *_content;
366  uint16 _numElements;
367  uint16 _selectedElement;
368 
369  const uint8 *_colorMap;
370  const uint16 _maxPathLen;
371  const bool _needsLocalizedFont;
372 
373  static uint8 _errorDialogDisplayed;
374 
375  Resource *_res;
376 };
377 
381 class SJISFontEoB1PC98 : public SJISFont {
382 public:
383  SJISFontEoB1PC98(Common::SharedPtr<Graphics::FontSJIS> &font, /*uint8 shadowColor,*/ const uint16 *convTable1, const uint16 *convTable2);
384  ~SJISFontEoB1PC98() override {}
385  int getCharWidth(uint16 c) const override;
386  void drawChar(uint16 c, byte *dst, int pitch, int) const override;
387 
388 private:
389  uint16 convert(uint16 c) const;
390  const uint16 *_convTable1, *_convTable2;
391  bool _defaultConv;
392 };
393 
397 class SJISFontEoB2PC98 : public SJISFont {
398 public:
399  SJISFontEoB2PC98(Common::SharedPtr<Graphics::FontSJIS> &font, /*uint8 shadowColor,*/ const char *convTable1, const char *convTable2);
400  ~SJISFontEoB2PC98() override {}
401  int getCharWidth(uint16 c) const override;
402  void drawChar(uint16 c, byte *dst, int pitch, int) const override;
403 
404 private:
405  uint16 convert(uint16 c) const;
406  const char *_convTable1, *_convTable2;
407  //bool _defaultConv;
408 };
409 
414 class Font12x12PC98 : public OldDOSFont{
415 public:
416  Font12x12PC98(uint8 shadowColor, const uint16 *convTable1, const uint16 *convTable2, const uint8 *lookupTable);
417  ~Font12x12PC98() override;
418  bool usesOverlay() const override { return true; }
419  Type getType() const override { return kJIS_X0201; }
420  int getHeight() const override { return _height >> 1; }
421  int getWidth() const override { return _width >> 1; }
422  int getCharWidth(uint16 c) const override { return _width >> 1; };
423  bool load(Common::SeekableReadStream &file) override;
424 
425 private:
426  uint16 convert(uint16 c) const override;
427  const uint16 *_convTable1, *_convTable2;
428  uint16 *_bmpOffs;
429 };
430 
435 class PC98Font : public OldDOSFont {
436 public:
437  PC98Font(uint8 shadowColor, bool useOverlay, int scaleV, const uint8 *convTable1 = 0, const char *convTable2 = 0, const char *convTable3 = 0);
438  ~PC98Font() override {}
439  bool load(Common::SeekableReadStream &file) override;
440  int getHeight() const override { return _outputHeight; }
441  int getWidth() const override { return _outputWidth; }
442  int getCharWidth(uint16 c) const override { return _outputWidth; };
443  Type getType() const override { return _type; }
444 
445 private:
446  uint16 convert(uint16 c) const override;
447  uint16 makeTwoByte(uint16 c) const;
448 
449  const uint8 *_convTable1;
450  const char *_convTable2, *_convTable3;
451 
452  int _outputHeight;
453  int _outputWidth;
454  const Type _type;
455 };
456 
460 class SJISFontLarge : public SJISFont {
461 public:
462  SJISFontLarge(Common::SharedPtr<Graphics::FontSJIS> &font);
463  ~SJISFontLarge() override {}
464 
465  int getHeight() const override;
466  int getWidth() const override;
467  int getCharWidth(uint16 c) const override;
468 
469  bool usesOverlay() const override { return false; }
470  void drawChar(uint16 c, byte *dst, int pitch, int) const override;
471 };
472 
476 class SJISFont12x12 : public Font {
477 public:
478  SJISFont12x12(const uint16 *searchTable);
479  ~SJISFont12x12() override { unload(); }
480 
481  bool load(Common::SeekableReadStream &file) override;
482  Type getType() const override { return kSJIS; }
483  bool usesOverlay() const override { return true; }
484  int getHeight() const override { return _height; }
485  int getWidth() const override { return _width; }
486  int getCharWidth(uint16 c) const override { return _width; }
487  void setColorMap(const uint8 *src) override { _colorMap = src; }
488  void drawChar(uint16 c, byte *dst, int pitch, int) const override;
489 
490 private:
491  void unload();
492 
493  uint8 *_data;
494  Common::HashMap<uint16, uint8> _searchTable;
495 
496  const uint8 *_colorMap;
497  const int _height, _width;
498 };
499 
500 class SegaCDFont : public Font {
501 public:
502  SegaCDFont(Common::Language lang, const uint16 *convTable1, const uint16 *convTable2, const uint8 *widthTable1, const uint8 *widthTable2, const uint8 *widthTable3);
503  ~SegaCDFont() override;
504 
505  bool load(Common::SeekableReadStream &file) override;
506  Type getType() const override { return _forceOneByte ? kASCII : kSJIS; }
507  int getHeight() const override { return _height; }
508  int getWidth() const override { return _width; }
509  int getCharWidth(uint16 c) const override;
510  int getCharHeight(uint16 c) const override;
511  void setStyles(int styles) override;
512  void setColorMap(const uint8 *src) override { _colorMap = src; }
513  void drawChar(uint16 c, byte *dst, int pitch, int bpp) const override { drawChar(c, dst, pitch, 0, 0); }
514  void drawChar(uint16 c, byte *dst, int pitch, int xOffs, int yOffs) const override;
515 
516 private:
517  const uint8 *getGlyphData(uint16 c, uint8 &charWidth, uint8 &charHeight, uint8 &pitch) const;
518 
519  const uint8 *_data;
520  const uint8 *_buffer;
521  bool _forceTwoByte;
522  bool _forceOneByte;
523  Common::Language _lang;
524  uint8 _style;
525 
526  const uint8 *_colorMap;
527  const int _height, _width;
528  const uint16 *_convTable1, *_convTable2;
529  const uint8 *_widthTable1, *_widthTable2, *_widthTable3;
530 };
531 
532 } // End of namespace Kyra
533 
534 #endif // ENABLE_EOB
535 
536 #endif
Definition: str.h:59
RenderMode
Definition: rendermode.h:48
Definition: path.h:52
Definition: atari-screen.h:60
Definition: stream.h:745
Definition: ptr.h:572
Type
Definition: log.h:33
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: hashmap.h:85
Definition: detection.h:27
Definition: stream.h:385
T MAX(T a, T b)
Definition: util.h:64
Definition: system.h:161
Definition: ptr.h:159
Language
Definition: language.h:45
Definition: atari-screen.h:44