ScummVM API documentation
screen.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_H
23 #define KYRA_SCREEN_H
24 
25 #include "common/util.h"
26 #include "common/func.h"
27 #include "common/list.h"
28 #include "common/array.h"
29 #include "common/rect.h"
30 #include "common/rendermode.h"
31 #include "common/stream.h"
32 #include "common/ptr.h"
33 
34 class OSystem;
35 
36 namespace Graphics {
37 class FontSJIS;
38 } // End of namespace Graphics
39 
40 namespace Kyra {
41 
42 typedef Common::Functor0<void> UpdateFunctor;
43 
44 class KyraEngine_v1;
45 class Screen;
46 
47 struct ScreenDim {
48  uint16 sx;
49  uint16 sy;
50  uint16 w;
51  uint16 h;
52  uint16 col1;
53  uint16 col2;
54  uint16 line;
55  uint16 column;
56 };
57 
61 class Font {
62 public:
63  /* Font types
64  * Currently, we actually only care about oneByte and twoByte, but
65  * naming it like this makes it easier to extend if the need arises.
66  */
67  enum Type {
68  kASCII = 0,
69  kJIS_X0201,
70  kSJIS,
71  kBIG5,
72  kJohab
73  };
74 
75 public:
76  virtual ~Font() {}
77 
81  virtual bool load(Common::SeekableReadStream &file) = 0;
82 
86  virtual bool usesOverlay() const { return false; }
87 
91  virtual Type getType() const = 0;
92 
96  virtual int getHeight() const = 0;
97 
102  virtual int getWidth() const = 0;
103 
107  virtual int getCharWidth(uint16 c) const = 0;
108 
113  virtual int getCharHeight(uint16 c) const { return getHeight(); }
114 
118  virtual void setColorMap(const uint8 *src) = 0;
119 
123  virtual void set16bitColorMap(const uint16 *src) {}
124 
125  enum FontStyle {
126  kStyleNone = 0,
127  kStyleLeftShadow = 1 << 0,
128  kStyleBorder = 1 << 1,
129  kStyleFat = 1 << 2,
130  kStyleNarrow1 = 1 << 3,
131  kStyleNarrow2 = 1 << 4,
132  kStyleFullWidth = 1 << 5,
133  kStyleForceOneByte = 1 << 6
134  };
135 
139  virtual void setStyles(int styles) {}
140 
149  virtual void drawChar(uint16 c, byte *dst, int pitch, int bpp) const = 0;
150 
151  virtual void drawChar(uint16 c, byte *dst, int pitch, int xOffs, int yOffs) const {}
152 };
153 
160 class DOSFont : public Font {
161 public:
162  DOSFont();
163  ~DOSFont() override { unload(); }
164 
165  bool load(Common::SeekableReadStream &file) override;
166  Type getType() const override { return kASCII; }
167  int getHeight() const override { return _height; }
168  int getWidth() const override { return _width; }
169  int getCharWidth(uint16 c) const override;
170  void setColorMap(const uint8 *src) override { _colorMap = src; }
171  void drawChar(uint16 c, byte *dst, int pitch, int) const override;
172 
173 private:
174  void unload();
175 
176  const uint8 *_colorMap;
177 
178  uint8 *_data;
179 
180  int _width, _height;
181 
182  int _numGlyphs;
183 
184  uint8 *_widthTable;
185  uint8 *_heightTable;
186  uint16 *_bitmapOffsets;
187 };
188 
192 class AMIGAFont : public Font {
193 public:
194  AMIGAFont();
195  ~AMIGAFont() override { unload(); }
196 
197  bool load(Common::SeekableReadStream &file) override;
198  Type getType() const override { return kASCII; }
199  int getHeight() const override { return _height; }
200  int getWidth() const override { return _width; }
201  int getCharWidth(uint16 c) const override;
202  void setColorMap(const uint8 *src) override {}
203  void drawChar(uint16 c, byte *dst, int pitch, int) const override;
204 
205 private:
206  void unload();
207 
208  int _width, _height;
209 
210  struct Character {
211  uint8 yOffset, xOffset, width;
212 
213  struct Graphics {
214  uint16 width, height;
215  uint8 *bitmap;
216  } graphics;
217  };
218 
219  Character _chars[255];
220 };
221 
225 class SJISFont : public Font {
226 public:
227  SJISFont(Common::SharedPtr<Graphics::FontSJIS> &font, const uint8 invisColor, bool is16Color, bool drawOutline, int extraSpacing);
228  ~SJISFont() override {}
229 
230  bool usesOverlay() const override { return true; }
231  Type getType() const override { return kSJIS; }
232 
233  bool load(Common::SeekableReadStream &) override { return true; }
234  int getHeight() const override;
235  int getWidth() const override;
236  int getCharWidth(uint16 c) const override;
237  void setColorMap(const uint8 *src) override;
238  void setStyles(int style) override { _style = style; }
239  void drawChar(uint16 c, byte *dst, int pitch, int) const override;
240 
241 protected:
242  const uint8 *_colorMap;
244  const bool _drawOutline;
245  int _style;
246 
247 private:
248  const uint8 _invisColor;
249  const bool _isTextMode;
250  // We use this for cases where the font width returned by getWidth() or getCharWidth() does not match the original.
251  // The original Japanese game versions use hard coded sjis font widths of 8 or 9. However, this does not necessarily
252  // depend on whether an outline is used or not (neither LOL/PC-9801 nor LOL/FM-TOWNS use an outline, but the first
253  // version uses a font width of 8 where the latter uses a font width of 9).
254  const int _sjisWidthOffset;
255 };
256 
257 class ChineseFont : public Font {
258 public:
259  ChineseFont(int pitch, int renderWidth, int renderHeight, int spacingWidth, int spacingHeight, int extraSpacingWidth, int extraSpacingHeight);
260  ~ChineseFont() override;
261 
262  virtual Type getType() const override { return kBIG5; }
263 
264  bool load(Common::SeekableReadStream &data) override;
265 
266  void setStyles(int styles) override { _border = (styles & kStyleBorder); }
267  int getHeight() const override { return _spacingHeight + (_border ? _borderExtraSpacingHeight : 0); }
268  int getWidth() const override { return _spacingWidth + (_border ? _borderExtraSpacingWidth : 0); }
269  int getCharWidth(uint16 c) const override { return hasGlyphForCharacter(c) ? getWidth() : -1; }
270  int getCharHeight(uint16 c) const override { return hasGlyphForCharacter(c) ? _renderHeight + (_border ? _borderExtraSpacingHeight : 0) : -1; }
271  void setColorMap(const uint8 *src) override;
272  void drawChar(uint16 c, byte *dst, int pitch, int) const override;
273 
274 protected:
275  uint32 getGlyphDataSize() const { return _glyphDataSize; }
276  uint16 _textColor[2];
277  bool _pixelColorShading;
278  const uint8 *_colorMap;
279  bool _border;
280 
281 private:
282  virtual bool hasGlyphForCharacter(uint16 c) const = 0;
283  virtual uint32 getFontOffset(uint16 c) const = 0;
284  virtual void processColorMap() = 0;
285 
286  const int _spacingWidth, _spacingHeight;
287  const int _borderExtraSpacingWidth, _borderExtraSpacingHeight;
288  const int _renderWidth, _renderHeight;
289 
290  const uint8 *_glyphData;
291  uint32 _glyphDataSize;
292  const uint16 _pitch;
293 };
294 
295 class JohabFontLoK final : public Font {
296 public:
297  JohabFontLoK(Font *&font8fat, const uint16 *lookupTable, uint32 lookupTableSize);
298  ~JohabFontLoK() override;
299 
300  enum {
301  kNumJongseong = 191,
302  kNumJungseong = 85,
303  kNumChoseong = 109
304  };
305 
306  bool load(Common::SeekableReadStream &data) override;
307  Type getType() const override { return kJohab; }
308  int getHeight() const override { return _height; }
309  int getWidth() const override { return _width; }
310  int getCharWidth(uint16 c) const override;
311  int getCharHeight(uint16 c) const override;
312  void setColorMap(const uint8 *src) override;
313  void drawChar(uint16 c, byte *dst, int pitch, int) const override;
314 
315 private:
316  const uint8 *createGlyph(uint16 chr) const;
317  void processColorMap();
318  void renderGlyph(byte *dst, const uint8 *glyph, uint8 col, int pitch) const;
319 
320  int _width, _height;
321  const uint8 *_colorMap;
322 
323  Font *&_font8fat;
324  const uint8 *_fileData;
325  const uint8 *_glyphData[3];
326  const uint16 *_2byteTables[7];
327  uint8 *_glyphTemp;
328 };
329 
330 class ChineseOneByteFontLoK final : public ChineseFont {
331 public:
332  ChineseOneByteFontLoK(int pitch);
333 private:
334  bool hasGlyphForCharacter(uint16 c) const override { return !(c & 0x80); }
335  uint32 getFontOffset(uint16 c) const override { return (c & 0x7F) * 14; }
336  void processColorMap() override;
337 };
338 
339 class ChineseTwoByteFontLoK final : public ChineseFont {
340 public:
341  ChineseTwoByteFontLoK(int pitch, const uint16 *lookupTable, uint32 lookupTableSize);
342 private:
343  bool hasGlyphForCharacter(uint16 c) const override;
344  uint32 getFontOffset(uint16 c) const override;
345  void processColorMap() override;
346 
347  const uint16 *_lookupTable;
348  uint32 _lookupTableSize;
349 };
350 
351 class ChineseOneByteFontMR final : public ChineseFont {
352 public:
353  ChineseOneByteFontMR(int pitch) : ChineseFont(pitch, 7, 14, 9, 14, 0, 2) {}
354 private:
355  bool hasGlyphForCharacter(uint16 c) const override { return (c == 0x6187) || !(c & 0x80); }
356  uint32 getFontOffset(uint16 c) const override { return ((c == 0x6187) ? 128 : (c & 0x7F)) * 14; }
357  void processColorMap() override;
358 };
359 
360 class ChineseTwoByteFontMR final : public ChineseFont {
361 public:
362  ChineseTwoByteFontMR(int pitch) : ChineseFont(pitch, 15, 14, 18, 14, 0, 2) {}
363 private:
364  bool hasGlyphForCharacter(uint16 c) const override { return (c != 0x6187) && (c & 0x80); }
365  uint32 getFontOffset(uint16 c) const override;
366  void processColorMap() override;
367 };
368 
369 #ifdef ENABLE_LOL
370 
371 class ChineseOneByteFontLoL final : public ChineseFont {
372 public:
373  ChineseOneByteFontLoL(int pitch) : ChineseFont(pitch, 8, 14, 8, 16, 0, 0) { _pixelColorShading = false; }
374  void setStyles(int styles) override {}
375 
376 private:
377  bool hasGlyphForCharacter(uint16 c) const override { return !(c & 0x80); }
378  uint32 getFontOffset(uint16 c) const override { return (c & 0x7F) * 14; }
379  void processColorMap() override;
380 };
381 
382 class ChineseTwoByteFontLoL final : public ChineseFont {
383 public:
384  ChineseTwoByteFontLoL(int pitch) : ChineseFont(pitch, 16, 14, 16, 16, 0, 0) { _pixelColorShading = false; }
385  void setStyles(int styles) override {}
386 
387 private:
388  bool hasGlyphForCharacter(uint16 c) const override { return (c & 0x80) && getFontOffset(c) < getGlyphDataSize(); }
389  uint32 getFontOffset(uint16 c) const override;
390  void processColorMap() override;
391 };
392 
393 #endif
394 
395 class ChineseOneByteFontHOF final : public ChineseFont {
396 public:
397  ChineseOneByteFontHOF(int pitch) : ChineseFont(pitch, 8, 14, 9, 15, 0, 0) {}
398 private:
399  bool hasGlyphForCharacter(uint16 c) const override { return !(c & 0x80); }
400  uint32 getFontOffset(uint16 c) const override { return (c & 0x7F) * 14; }
401  void processColorMap() override;
402 };
403 
404 class ChineseTwoByteFontHOF final : public ChineseFont {
405 public:
406  ChineseTwoByteFontHOF(int pitch) : ChineseFont(pitch, 16, 14, 18, 15, 0, 0) {}
407 private:
408  bool hasGlyphForCharacter(uint16 c) const override { return (c & 0x80); }
409  uint32 getFontOffset(uint16 c) const override;
410  void processColorMap() override;
411 };
412 
413 class MultiSubsetFont final : public Font {
414 public:
415  MultiSubsetFont(Common::Array<Font*> *subsets) : Font(), _subsets(subsets) {}
416  ~MultiSubsetFont() override;
417  Type getType() const override { return kBIG5; }
418 
419  // Caveat: This method will try to load a font into the first subset slot it finds.
420  // It expects the load method of the subset font to return false if the slot has
421  // already been filled. It will then try the next slot. So, unlike other fonts the
422  // subset fonts cannot be allowed to call the load method as often as they want
423  // (which we never did anyway - we only ever load each font exactly one time).
424  // But this also means that different
425  bool load(Common::SeekableReadStream &data) override;
426 
427  void setStyles(int styles) override;
428  int getHeight() const override;
429  int getWidth() const override;
430  int getCharWidth(uint16 c) const override;
431  int getCharHeight(uint16 c) const override;
432  void setColorMap(const uint8 *src) override;
433  void drawChar(uint16 c, byte *dst, int pitch, int) const override;
434 
435 private:
436  Common::Array<Font*> *_subsets;
437 };
438 
444 class Palette {
445 public:
446  Palette(const int numColors);
447  ~Palette();
448 
449  enum {
450  kVGABytesPerColor = 3,
451  kPC98BytesPerColor = 3,
452  kAmigaBytesPerColor = 2
453  };
454 
458  void loadVGAPalette(Common::ReadStream &stream, int startIndex, int colors);
459 
463  void loadHiColorPalette(Common::ReadStream &stream, int startIndex, int colors);
464 
468  void loadEGAPalette(Common::ReadStream &stream, int startIndex, int colors);
469 
474  kIntensityLow = 0,
475  kIntensityHigh = 1
476  };
477 
478  void setCGAPalette(int palIndex, CGAIntensity intensity);
479 
483  void loadAmigaPalette(Common::ReadStream &stream, int startIndex, int colors);
484 
488  void loadPC98Palette(Common::ReadStream &stream, int startIndex, int colors);
489 
493  int getNumColors() const { return _numColors; }
494 
498  void clear();
499 
507  void fill(int firstCol, int numCols, uint8 value);
508 
517  void copy(const Palette &source, int firstCol = 0, int numCols = -1, int dstStart = -1);
518 
527  void copy(const uint8 *source, int firstCol, int numCols, int dstStart = -1);
528 
534  uint8 *fetchRealPalette() const;
535 
536  //XXX
537  uint8 &operator[](const int index) {
538  assert(index >= 0 && index <= _numColors * 3);
539  return _palData[index];
540  }
541 
542  const uint8 &operator[](const int index) const {
543  assert(index >= 0 && index <= _numColors * 3);
544  return _palData[index];
545  }
546 
552  uint8 *getData() { return _palData; }
553  const uint8 *getData() const { return _palData; }
554 
555 private:
556  uint8 *_palData;
557  const int _numColors;
558 
559  static const uint8 _egaColors[];
560  static const int _egaNumColors;
561  static const uint8 _cgaColors[4][12];
562  static const int _cgaNumColors;
563 };
564 
565 class Screen {
566 public:
567  enum {
568  SCREEN_W = 320,
569  SCREEN_H = 200,
570  SCREEN_H_SEGA_NTSC = 224,
571  SCREEN_PAGE_SIZE = 320 * 200 + 1024,
572  SCREEN_OVL_SJIS_SIZE = 640 * 400,
573  SCREEN_PAGE_NUM = 16,
574  SCREEN_OVLS_NUM = 6,
575 
576  SCREEN_IDLEREFRESH_RESTART_MSEC = 250,
577  SCREEN_IDLEREFRESH_RATE_MSEC = 16
578  };
579 
580  enum CopyRegionFlags {
581  CR_NO_P_CHECK = 0x01
582  };
583 
584  enum DrawShapeFlags {
585  kDRAWSHP_XFLIP = 0x01,
586  kDRAWSHP_YFLIP = 0x02,
587  kDRAWSHP_SCALE = 0x04,
588  kDRAWSHP_WINREL = 0x10,
589  kDRAWSHP_CENTER = 0x20,
590  kDRAWSHP_FADE = 0x100,
591  kDRAWSHP_PREDATOR = 0x200,
592  kDRAWSHP_COMPACT = 0x400,
593  kDRAWSHP_PRIORITY = 0x800,
594  kDRAWSHP_TRANSPARENT = 0x1000,
595  kDRAWSHP_BCKGRNDFADE = 0x2000,
596  kDRAWSHP_MORPH = 0x4000,
597  kDRAWSHP_COLOR = 0x8000
598  };
599 
600  enum FontId {
601  FID_6_FNT = 0,
602  FID_8_FNT,
603  FID_9_FNT,
604  FID_CRED6_FNT,
605  FID_CRED8_FNT,
606  FID_BOOKFONT_FNT,
607  FID_GOLDFONT_FNT,
608  FID_INTRO_FNT,
609  FID_SJIS_FNT,
610  FID_SJIS_TEXTMODE_FNT,
611  FID_SJIS_LARGE_FNT,
612  FID_SJIS_SMALL_FNT,
613  FID_CHINESE_FNT,
614  FID_KOREAN_FNT,
615  FID_NUM
616  };
617 
618  Screen(KyraEngine_v1 *vm, OSystem *system, const ScreenDim *dimTable, const int dimTableSize);
619  virtual ~Screen();
620 
621  // init
622  virtual bool init();
623  virtual void setResolution();
624  virtual void enableHiColorMode(bool enabled);
625 
626  // refresh
627  int updateScreen();
628  void updateBackendScreen(bool force);
629 
630  uint32 _idleUpdateTimer;
631 
632  // debug functions
633  bool queryScreenDebug() const { return _debugEnabled; }
634  bool enableScreenDebug(bool enable);
635 
636  // page cur. functions
637  int setCurPage(int pageNum);
638  void clearCurPage();
639 
640  void copyWsaRect(int x, int y, int w, int h, int dimState, int plotFunc, const uint8 *src,
641  int unk1, const uint8 *unkPtr1, const uint8 *unkPtr2);
642 
643  // page 0 functions
644  void copyToPage0(int y, int h, uint8 page, uint8 *seqBuf);
645  void shakeScreen(int times);
646 
647  // page functions
648  void copyRegion(int x1, int y1, int x2, int y2, int w, int h, int srcPage, int dstPage, int flags=0);
649  void copyPage(uint8 srcPage, uint8 dstPage);
650 
651  void copyRegionToBuffer(int pageNum, int x, int y, int w, int h, uint8 *dest);
652  void copyBlockToPage(int pageNum, int x, int y, int w, int h, const uint8 *src);
653 
654  void shuffleScreen(int sx, int sy, int w, int h, int srcPage, int dstPage, int ticks, bool transparent);
655  void fillRect(int x1, int y1, int x2, int y2, uint8 color, int pageNum = -1, bool xored = false);
656 
657  void clearPage(int pageNum);
658 
659  int getPagePixel(int pageNum, int x, int y);
660  void setPagePixel(int pageNum, int x, int y, uint8 color);
661 
662  const uint8 *getCPagePtr(int pageNum) const;
663  uint8 *getPageRect(int pageNum, int x, int y, int w, int h);
664 
665  // palette handling
666  void fadeFromBlack(int delay=0x54, const UpdateFunctor *upFunc = 0);
667  void fadeToBlack(int delay=0x54, const UpdateFunctor *upFunc = 0);
668 
669  virtual void fadePalette(const Palette &pal, int delay, const UpdateFunctor *upFunc = 0);
670  virtual void getFadeParams(const Palette &pal, int delay, int &delayInc, int &diff);
671  virtual int fadePalStep(const Palette &pal, int diff);
672 
673  void setPaletteIndex(uint8 index, uint8 red, uint8 green, uint8 blue);
674  virtual void setScreenPalette(const Palette &pal);
675 
676  // SegaCD version
677  // This is a somewhat hacky but probably least invasive way to
678  // move the whole ingame screen output down a couple of lines.
679  void transposeScreenOutputY(int yAdd);
680 
681  // AMIGA version only
682  bool isInterfacePaletteEnabled() const { return _dualPaletteModeSplitY; }
683  void enableDualPaletteMode(int splitY);
684  void disableDualPaletteMode();
685 
686  virtual void getRealPalette(int num, uint8 *dst);
687  Palette &getPalette(int num);
688  void copyPalette(const int dst, const int src);
689 
690  // gui specific (processing on _curPage)
691  void drawLine(bool vertical, int x, int y, int length, int color);
692  void drawClippedLine(int x1, int y1, int x2, int y2, int color);
693  virtual void drawShadedBox(int x1, int y1, int x2, int y2, int color1, int color2);
694  void drawBox(int x1, int y1, int x2, int y2, int color);
695 
696  // font/text handling
697  virtual bool loadFont(FontId fontId, const char *filename);
698  FontId setFont(FontId fontId);
699 
700  int getFontHeight() const;
701  int getFontWidth() const;
702 
703  int getCharWidth(uint16 c) const;
704  int getCharHeight(uint16 c) const;
705  int getTextWidth(const char *str, bool nextWordOnly = false);
706  int getNumberOfCharacters(const char *str);
707 
708  void printText(const char *str, int x, int y, uint8 color1, uint8 color2, int pitch = -1);
709 
710  virtual void setTextColorMap(const uint8 *cmap) = 0;
711  void setTextColor(const uint8 *cmap, int a, int b);
712  void setTextColor16bit(const uint16 *cmap16);
713  int setFontStyles(FontId fontId, int styles);
714 
715  const ScreenDim *getScreenDim(int dim) const;
716  void modifyScreenDim(int dim, int x, int y, int w, int h);
717  int screenDimTableCount() const { return _dimTableCount; }
718 
719  void setScreenDim(int dim);
720  int curDimIndex() const { return _curDimIndex; }
721 
722  void setTextMarginRight(int x) { _textMarginRight = x; }
723  uint16 _textMarginRight;
724  bool _overdrawMargin;
725 
726  const ScreenDim *_curDim;
727 
728  Common::String _lineBreakChars;
729 
730  // shape handling
731  uint8 *encodeShape(int x, int y, int w, int h, int flags);
732 
733  int setNewShapeHeight(uint8 *shape, int height);
734  int resetShapeHeight(uint8 *shape);
735 
736  virtual void drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int sd, int flags, ...);
737 
738  // mouse handling
739  void hideMouse();
740  void showMouse();
741  bool isMouseVisible() const;
742  virtual void setMouseCursor(int x, int y, const byte *shape);
743 
744  // rect handling
745  virtual int getRectSize(int w, int h) = 0;
746 
747  void rectClip(int &x, int &y, int w, int h);
748 
749  // misc
750  virtual void loadBitmap(const char *filename, int tempPage, int dstPage, Palette *pal, bool skip=false);
751 
752  virtual bool loadPalette(const char *filename, Palette &pal);
753  bool loadPaletteTable(const char *filename, int firstPalette);
754  virtual void loadPalette(const byte *data, Palette &pal, int bytes);
755 
756  void setAnimBlockPtr(int size);
757 
758  void setShapePages(int page1, int page2, int minY = -1, int maxY = 201);
759 
760  virtual byte getShapeFlag1(int x, int y);
761  virtual byte getShapeFlag2(int x, int y);
762 
763  virtual int getDrawLayer(int x, int y);
764  virtual int getDrawLayer2(int x, int y, int height);
765 
766  void blockInRegion(int x, int y, int width, int height);
767  void blockOutRegion(int x, int y, int width, int height);
768 
769  int _charSpacing;
770  int _lineSpacing;
771  int _curPage;
772  uint8 *_shapePages[2];
773  int _maskMinY, _maskMaxY;
774  FontId _currentFont;
775 
776  // decoding functions
777  static void decodeFrame1(const uint8 *src, uint8 *dst, uint32 size);
778  static uint16 decodeEGAGetCode(const uint8 *&pos, uint8 &nib);
779 
780  static void decodeFrame3(const uint8 *src, uint8 *dst, uint32 size, bool isAmiga);
781  static uint decodeFrame4(const uint8 *src, uint8 *dst, uint32 dstSize);
782  static void decodeFrameDelta(uint8 *dst, const uint8 *src, bool noXor = false);
783  static void decodeFrameDeltaPage(uint8 *dst, const uint8 *src, const int pitch, bool noXor);
784 
785  static void convertAmigaGfx(uint8 *data, int w, int h, int depth = 5, bool wsa = false, int bytesPerPlane = -1);
786  static void convertAmigaMsc(uint8 *data);
787 
788  // This seems to be a variant of shuffleScreen (which is used in LoK). At the time of coding (and long after that) the
789  // fact that this is a double implementation went unnoticed. My - admittedly limited - efforts to get rid of one of these
790  // implementations were unsatisfactory, though. Each method seems to be optimized to produce accurate results for its
791  // specifc purpose (LoK for shuffleScreen, EoB/LoL for crossFadeRegion). Merging these methods has no priority, since we
792  // can well afford the 20 lines of extra code.
793  void crossFadeRegion(int x1, int y1, int x2, int y2, int w, int h, int srcPage, int dstPage);
794 
795  uint16 *get16bitPalette() { return _16bitPalette; }
796  void set16bitShadingLevel(int lvl) { _16bitShadingLevel = lvl; }
797 
798 protected:
799  void resetPagePtrsAndBuffers(int pageSize);
800  uint8 *getPagePtr(int pageNum);
801  virtual void updateDirtyRects();
802  void updateDirtyRectsAmiga();
803  void updateDirtyRectsOvl();
804 
805  template<typename srcType, typename scaleToType> void scale2x(uint8 *dst, int dstPitch, const uint8 *src, int srcPitch, int w, int h);
806  template<typename pixelType> void mergeOverlayImpl(int x, int y, int w, int h);
807  virtual void mergeOverlay(int x, int y, int w, int h) {
808  if (_useHiColorScreen)
809  mergeOverlayImpl<uint16>(x, y, w, h);
810  else
811  mergeOverlayImpl<uint8>(x, y, w, h);
812  }
813 
814  // overlay specific
815  byte *getOverlayPtr(int pageNum);
816  void clearOverlayPage(int pageNum);
817  void clearOverlayRect(int pageNum, int x, int y, int w, int h);
818  void copyOverlayRegion(int x, int y, int x2, int y2, int w, int h, int srcPage, int dstPage);
819 
820  // font/text specific
821  uint16 fetchChar(const char *&s) const;
822  void drawChar(uint16 c, int x, int y, int pitch = -1);
823 
824  int16 encodeShapeAndCalculateSize(uint8 *from, uint8 *to, int size);
825 
826  template<bool noXor> static void wrapped_decodeFrameDelta(uint8 *dst, const uint8 *src);
827  template<bool noXor> static void wrapped_decodeFrameDeltaPage(uint8 *dst, const uint8 *src, const int pitch);
828 
829  uint8 *_pagePtrs[16];
830  const uint8 *_pagePtrsBuff;
831  uint8 *_sjisOverlayPtrs[SCREEN_OVLS_NUM];
832  uint8 _pageMapping[SCREEN_PAGE_NUM];
833 
834  bool _useOverlays;
835  bool _useSJIS;
836  int _fontStyles;
837 
838  Font *_fonts[FID_NUM];
839  uint8 _textColorsMap[16];
840  uint16 _textColorsMap16bit[2];
841 
842  uint8 *_textRenderBuffer;
843  int _textRenderBufferSize;
844 
846  uint8 _sjisInvisibleColor;
847  bool _sjisMixedFontMode;
848 
849  // colors/palette specific
850  bool _use16ColorMode;
851  bool _useShapeShading;
852  bool _4bitPixelPacking;
853  bool _useHiResEGADithering;
854  bool _useHiColorScreen;
855  bool _isAmiga;
856  bool _useAmigaExtraColors;
857  bool _isSegaCD;
858  Common::RenderMode _renderMode;
859  int _bytesPerPixel;
860  int _screenPageSize;
861  const int _screenHeight;
862  int _yTransOffs;
863 
864  Palette *_screenPalette;
865  Common::Array<Palette *> _palettes;
866  Palette *_internFadePalette;
867 
868  uint16 shade16bitColor(uint16 col);
869 
870  uint16 *_16bitPalette;
871  uint16 *_16bitConversionPalette;
872  uint8 _16bitShadingLevel;
873 
874  uint8 *_animBlockPtr;
875  int _animBlockSize;
876 
877  // dimension handling
878  const ScreenDim *const _dimTable;
879  ScreenDim **_customDimTable;
880  const int _dimTableCount;
881  int _curDimIndex;
882 
883  // mouse handling
884  int _mouseLockCount;
885  const uint8 _cursorColorKey;
886 
887  virtual void postProcessCursor(uint8 *data, int w, int h, int pitch) {}
888 
889  enum {
890  kMaxDirtyRects = 50
891  };
892 
893  bool _forceFullUpdate;
894  bool _paletteChanged;
895  Common::List<Common::Rect> _dirtyRects;
896 
897  void addDirtyRect(int x, int y, int w, int h);
898 
899  OSystem *_system;
900  KyraEngine_v1 *_vm;
901 
902  // shape
903  typedef void (Screen::*DsPlotFunc)(uint8*, uint8);
904  typedef int (Screen::*DsMarginSkipFunc)(uint8*&, const uint8*&, int&);
905  typedef void (Screen::*DsLineFunc)(uint8*&, const uint8*&, const DsPlotFunc, int&, int16);
906 
907  int drawShapeMarginNoScaleUpwind(uint8 *&dst, const uint8 *&src, int &cnt);
908  int drawShapeMarginNoScaleDownwind(uint8 *&dst, const uint8 *&src, int &cnt);
909  int drawShapeMarginScaleUpwind(uint8 *&dst, const uint8 *&src, int &cnt);
910  int drawShapeMarginScaleDownwind(uint8 *&dst, const uint8 *&src, int &cnt);
911  int drawShapeSkipScaleUpwind(uint8 *&dst, const uint8 *&src, int &cnt);
912  int drawShapeSkipScaleDownwind(uint8 *&dst, const uint8 *&src, int &cnt);
913  void drawShapeProcessLineNoScaleUpwind(uint8 *&dst, const uint8 *&src, const DsPlotFunc plot, int &cnt, int16);
914  void drawShapeProcessLineNoScaleDownwind(uint8 *&dst, const uint8 *&src, const DsPlotFunc plot, int &cnt, int16);
915  void drawShapeProcessLineScaleUpwind(uint8 *&dst, const uint8 *&src, const DsPlotFunc plot, int &cnt, int16 scaleState);
916  void drawShapeProcessLineScaleDownwind(uint8 *&dst, const uint8 *&src, const DsPlotFunc plot, int &cnt, int16 scaleState);
917 
918  void drawShapePlotType0(uint8 *dst, uint8 cmd);
919  void drawShapePlotType1(uint8 *dst, uint8 cmd);
920  void drawShapePlotType3_7(uint8 *dst, uint8 cmd);
921  void drawShapePlotType4(uint8 *dst, uint8 cmd);
922  void drawShapePlotType5(uint8 *dst, uint8 cmd);
923  void drawShapePlotType6(uint8 *dst, uint8 cmd);
924  void drawShapePlotType8(uint8 *dst, uint8 cmd);
925  void drawShapePlotType9(uint8 *dst, uint8 cmd);
926  void drawShapePlotType11_15(uint8 *dst, uint8 cmd);
927  void drawShapePlotType12(uint8 *dst, uint8 cmd);
928  void drawShapePlotType13(uint8 *dst, uint8 cmd);
929  void drawShapePlotType14(uint8 *dst, uint8 cmd);
930  void drawShapePlotType16(uint8 *dst, uint8 cmd);
931  void drawShapePlotType20(uint8 *dst, uint8 cmd);
932  void drawShapePlotType21(uint8 *dst, uint8 cmd);
933  void drawShapePlotType33(uint8 *dst, uint8 cmd);
934  void drawShapePlotType37(uint8 *dst, uint8 cmd);
935  void drawShapePlotType48(uint8 *dst, uint8 cmd);
936  void drawShapePlotType52(uint8 *dst, uint8 cmd);
937 
938  const uint8 *_dsShapeFadingTable;
939  int _dsShapeFadingLevel;
940  const uint8 *_dsColorTable;
941  const uint8 *_dsTransparencyTable1;
942  const uint8 *_dsTransparencyTable2;
943  const uint8 *_dsBackgroundFadingTable;
944  int _dsDrawLayer;
945  uint8 *_dsDstPage;
946  int _dsTmpWidth;
947  int _dsOffscreenLeft;
948  int _dsOffscreenRight;
949  int _dsScaleW;
950  int _dsScaleH;
951  int _dsOffscreenScaleVal1;
952  int _dsOffscreenScaleVal2;
953  int _drawShapeVar1;
954  int _drawShapeVar3;
955  int _drawShapeVar4;
956  int _drawShapeVar5;
957 
958  // AMIGA version
959  int _dualPaletteModeSplitY;
960 
961  // debug
962  bool _debugEnabled;
963 };
964 
965 } // End of namespace Kyra
966 
967 #endif
void setColorMap(const uint8 *src) override
Definition: screen.h:202
int getNumColors() const
Definition: screen.h:493
uint8 * getData()
Definition: screen.h:552
int getHeight() const override
Definition: screen.h:308
bool load(Common::SeekableReadStream &) override
Definition: screen.h:233
Definition: str.h:59
int getHeight() const override
Definition: screen.h:167
Definition: screen.h:360
bool usesOverlay() const override
Definition: screen.h:230
Definition: screen.h:257
Definition: screen.h:225
Definition: array.h:52
Definition: screen.h:351
virtual void setStyles(int styles)
Definition: screen.h:139
Definition: kyra_v1.h:126
Definition: screen.h:565
Definition: screen.h:160
Type getType() const override
Definition: screen.h:198
Definition: screen.h:413
RenderMode
Definition: rendermode.h:48
virtual Type getType() const override
Definition: screen.h:262
Definition: screen.h:192
Definition: atari-screen.h:60
void setStyles(int style) override
Definition: screen.h:238
virtual bool usesOverlay() const
Definition: screen.h:86
Definition: stream.h:745
int getHeight() const override
Definition: screen.h:199
Out copy(In first, In last, Out dst)
Definition: algorithm.h:52
virtual void set16bitColorMap(const uint16 *src)
Definition: screen.h:123
Definition: screen.h:339
Definition: formatinfo.h:28
Type getType() const override
Definition: screen.h:166
int getCharHeight(uint16 c) const override
Definition: screen.h:270
void setStyles(int styles) override
Definition: screen.h:266
Definition: screen.h:444
Definition: screen.h:395
void setColorMap(const uint8 *src) override
Definition: screen.h:170
Definition: detection.h:27
Definition: screen.h:330
Definition: screen.h:295
int getWidth() const override
Definition: screen.h:309
int getWidth() const override
Definition: screen.h:200
signed char * fill(signed char *first, signed char *last, Value val)
Definition: algorithm.h:168
Type getType() const override
Definition: screen.h:231
Definition: screen.h:47
Definition: stream.h:385
Definition: screen.h:404
int getCharWidth(uint16 c) const override
Definition: screen.h:269
Type getType() const override
Definition: screen.h:417
Definition: system.h:161
Type getType() const override
Definition: screen.h:307
int getWidth() const override
Definition: screen.h:168
CGAIntensity
Definition: screen.h:473
int getHeight() const override
Definition: screen.h:267
int getWidth() const override
Definition: screen.h:268
Definition: screen.h:61
virtual int getCharHeight(uint16 c) const
Definition: screen.h:113