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