ScummVM API documentation
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
31namespace Kyra {
32
33class EoBCoreEngine;
34class SegaRenderer;
35class SegaAnimator;
36class Screen_EoB : public Screen {
37friend class SegaRenderer;
38public:
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
55public:
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 createColorFadeTable(const uint8 *palData, uint8 *dst, uint8 rootColor, uint8 weight);
106 void createHiColorFadeTable(const uint16 *palData, void *dst, uint8 rootColor, uint8 weight);
107
108 const uint16 *getCGADitheringTable(int index) const;
109 const uint8 *getEGADitheringTable() const;
110 int bytesPerPixel() const;
111
112 bool loadFont(FontId fontId, const char *filename) override;
113
114 // FM-Towns specific
115 void decodeSHP(const uint8 *data, int dstPage);
116 void convertToHiColor(int page);
117 void shadeRect(int x1, int y1, int x2, int y2, int shadingLevel);
118
119 // PC-98 specific
120 void selectPC98Palette(int palID, Palette &dest, int brightness = 0, bool set = false);
121 void decodeBIN(const uint8 *src, uint8 *dst, uint16 inSize);
122 void decodePC98PlanarBitmap(uint8 *srcDstBuffer, uint8 *tmpBuffer, uint16 size = 64000);
123
124 struct PalCycleData {
125 const int8 *data;
126 uint8 delay;
127 };
128
129 void initPC98PaletteCycle(int palID, PalCycleData *data);
130 void updatePC98PaletteCycle(int brightness);
131
132 PalCycleData *_activePalCycle;
133 uint8 *_cyclePalette;
134
135 // Amiga specific
136 void loadSpecialAmigaCPS(const char *fileName, int destPage, bool isGraphics);
137 // This is a simple way of emulating the Amiga copper list palette magic for more than 32 colors.
138 // I use colors 32 to 63 for these extra colors (which the Amiga copper sends to the color
139 // registers on the fly at vertical beam position 120).
140 void setDualPalettes(Palette &top, Palette &bottom);
141
142 // SegaCD specific
143 void sega_initGraphics();
144 void sega_selectPalette(int srcPalID, int dstPalID, bool set = false);
145 void sega_loadCustomPaletteData(Common::ReadStream *in);
146 void sega_updatePaletteFaders(int palID);
147 void sega_fadePalette(int delay, int16 brEnd, int dstPalID = -1, bool waitForCompletion = true, bool noUpdate = false);
148 void sega_fadeToBlack(int delay) { sega_fadePalette(delay, -7); }
149 void sega_fadeToWhite(int delay) { sega_fadePalette(delay, 7); }
150 void sega_fadeToNeutral(int delay) { sega_fadePalette(delay, 0); }
151 void sega_paletteOps(int16 opPal, int16 par1, int16 par2);
152 void sega_setTextBuffer(uint8 *buffer, uint32 bufferSize);
153 void sega_clearTextBuffer(uint8 col);
154 void sega_loadTextBackground(const uint8 *src, uint16 size);
155 void sega_drawTextBox(int pW, int pH, int x, int y, int w, int h, uint8 color1, uint8 color2);
156 void sega_loadTextBufferToVRAM(uint16 srcOffset, uint16 addr, int size);
157 void sega_gfxScale(uint8 *out, uint16 w, uint16 h, uint16 pitch, const uint8 *in, const uint16 *stampMap, const uint16 *traceVectors);
158 void sega_drawClippedLine(int pW, int pH, int x, int y, int w, int h, uint8 color);
159 uint8 *sega_convertShape(const uint8 *src, int w, int h, int pal, int hOffs = 0);
160 void sega_encodeShapesFromSprites(const uint8 **dst, const uint8 *src, int numShapes, int w, int h, int pal, bool removeSprites = true);
161
162 SegaRenderer *sega_getRenderer() const { return _segaRenderer; }
163 SegaAnimator *sega_getAnimator() const { return _segaAnimator; }
164
165private:
166 void updateDirtyRects() override;
167 void ditherRect(const uint8 *src, uint8 *dst, int dstPitch, int srcW, int srcH, int colorKey = -1);
168
169 template<typename pixelType , bool shapeFading> void drawShapeSetPixel(uint8 *dst, uint8 col);
170 void scaleShapeProcessLine2Bit(uint8 *&shpDst, const uint8 *&shpSrc, uint32 transOffsetDst, uint32 transOffsetSrc);
171 void scaleShapeProcessLine4Bit(uint8 *&dst, const uint8 *&src);
172 bool posWithinRect(int posX, int posY, int x1, int y1, int x2, int y2);
173
174 void setPagePixelHiCol(int pageNum, int x, int y, int color);
175
176 void generateEGADitheringTable(const Palette &pal);
177 void generateCGADitheringTables(const uint8 *mappingData);
178
179 typedef void (Screen_EoB::*DrawShapePlotFunc)(uint8*, uint8);
180 DrawShapePlotFunc _drawShapeSetPixel;
181
182 int _dsDiv, _dsRem, _dsScaleTrans;
183 uint8 *_cgaScaleTable;
184 int16 _gfxX, _gfxY;
185 int _gfxCol;
186 const uint8 *_gfxMaxY;
187
188 int16 _dsX1, _dsX2, _dsY1, _dsY2;
189
190 bool _dsBackgroundFading;
191 int16 _dsBackgroundFadingXOffs;
192 uint8 _shapeOverlay[16];
193
194 uint8 *_dsTempPage;
195 uint8 *_shpBuffer;
196 uint8 *_hiColorConvertBuffer;
197
198 uint16 *_cgaDitheringTables[2];
199 const uint8 *_cgaMappingDefault;
200
201 uint8 *_egaDitheringTable;
202 uint8 *_egaDitheringTempPage;
203
204 Common::String _cpsFilePattern;
205
206 const uint16 _hiColorCursorColorKey;
207
208 static const uint8 _egaMatchTable[];
209 static const ScreenDim _screenDimTableIntl[];
210 static const ScreenDim _screenDimTableZH[];
211 static const int _screenDimTableCount;
212
213 // SegaCD specific
214 struct PaletteFader {
215 PaletteFader() : _brCur(0), _brDest(0), _fadeIncr(0), _fadeDelay(0), _fadeTimer(0), _needRefresh(false) {}
216 int16 _brCur;
217 int16 _brDest;
218 int16 _fadeIncr;
219 int16 _fadeDelay;
220 int16 _fadeTimer;
221 bool _needRefresh;
222 };
223
224 PaletteFader *_palFaders;
225 bool _specialColorReplace;
226 SegaRenderer *_segaRenderer;
227 SegaAnimator *_segaAnimator;
228 uint16 _segaCurPalette[64];
229 uint16 *_segaCustomPalettes;
230 uint8 *_defaultRenderBuffer;
231 int _defaultRenderBufferSize;
232
234};
235
236class ChineseTwoByteFontEoB final : public Font {
237public:
238 ChineseTwoByteFontEoB(Common::SharedPtr<Graphics::Big5Font> big5, Font *singleByte) : _big5(big5), _singleByte(singleByte), _border(false), _colorMap(nullptr) {}
239
240 virtual Type getType() const override { return kBIG5; }
241
242 bool load(Common::SeekableReadStream &data) override {
243 return _singleByte->load(data);
244 }
245
246 void setStyles(int styles) override { _border = (styles & kStyleBorder); _singleByte->setStyles(styles); }
247 int getHeight() const override { return MAX(_big5->getFontHeight(), _singleByte->getHeight()); }
248 int getWidth() const override { return MAX(_big5->kChineseTraditionalWidth + 2, _singleByte->getWidth()); }
249 void setColorMap(const uint8 *src) override { _colorMap = src; _singleByte->setColorMap(src); }
250 int getCharWidth(uint16 c) const override;
251 int getCharHeight(uint16 c) const override;
252 void drawChar(uint16 c, byte *dst, int pitch, int bpp) const override;
253
254private:
255 uint16 translateBig5(uint16 in) const;
257 Common::ScopedPtr<Font> _singleByte;
258 bool _border;
259 const uint8 *_colorMap;
260};
261
267class OldDOSFont : public Font {
268public:
269 OldDOSFont(Common::RenderMode mode, uint8 shadowColor, bool remapCharacters = true);
270 ~OldDOSFont() override;
271
272 bool load(Common::SeekableReadStream &file) override;
273 bool loadPCBIOSTall();
274 Type getType() const override { return kASCII; }
275 int getHeight() const override { return _height; }
276 int getWidth() const override { return _width; }
277 bool usesOverlay() const override { return _useOverlay; }
278 int getCharWidth(uint16 c) const override;
279 void setColorMap(const uint8 *src) override;
280 void setHiColorMap(const uint32 *src) override { _hiColorMap = src; }
281 void setStyles(int styles) override { _style = styles; }
282 void drawChar(uint16 c, byte *dst, int pitch, int bpp) const override;
283
284protected:
285 void unload();
286
287 int _style;
288 const uint8 *_colorMap8bit;
289 uint8 *_data;
290 uint16 *_bitmapOffsets;
291 int _width, _height;
292 int _numGlyphs;
293 uint8 _shadowColor;
294
295 uint16 _numGlyphsMax;
296 bool _useOverlay;
297 int _scaleV;
298
299private:
300 void drawCharIntern(uint16 c, byte *dst, int pitch, int bpp, int col1, int col2) const;
301 virtual uint16 convert(uint16 c) const;
302 Common::RenderMode _renderMode;
303 const uint32 *_hiColorMap;
304 bool _remapCharacters;
305
306 static uint16 *_cgaDitheringTable;
307 static int _numRef;
308};
309
313class Resource;
314class AmigaDOSFont : public Font {
315public:
316 AmigaDOSFont(Resource *res, bool needsLocalizedFont = false);
317 ~AmigaDOSFont() override { unload(); }
318
319 bool load(Common::SeekableReadStream &file) override;
320 Type getType() const override { return kASCII; }
321 int getHeight() const override { return _height; }
322 int getWidth() const override { return _width; }
323 int getCharWidth(uint16 c) const override;
324 void setColorMap(const uint8 *src) override { _colorMap = src; }
325 void drawChar(uint16 c, byte *dst, int pitch, int) const override;
326
327 static void errorDialog(int index);
328
329private:
330 void unload();
331
332 struct TextFont {
333 TextFont() : data(0), bitmap(0), location(0), spacing(0), kerning(0), height(0), width(0), baseLine(0), firstChar(0), lastChar(0), modulo(0) {}
334 ~TextFont() {
335 delete[] data;
336 }
337
338 uint16 height;
339 uint16 width;
340 uint16 baseLine;
341 uint8 firstChar;
342 uint8 lastChar;
343 uint16 modulo;
344 const uint8 *data;
345 const uint8 *bitmap;
346 const uint16 *location;
347 const int16 *spacing;
348 const int16 *kerning;
349 };
350
351 TextFont *loadContentFile(const Common::Path &fileName);
352 void selectMode(int mode);
353
354 struct FontContent {
355 FontContent() : height(0), style(0), flags(0) {}
356 ~FontContent() {
357 data.reset();
358 }
359
360 Common::String contentFile;
362 uint16 height;
363 uint8 style;
364 uint8 flags;
365 };
366
367 int _width, _height;
368 uint8 _first, _last;
369 FontContent *_content;
370 uint16 _numElements;
371 uint16 _selectedElement;
372
373 const uint8 *_colorMap;
374 const uint16 _maxPathLen;
375 const bool _needsLocalizedFont;
376
377 static uint8 _errorDialogDisplayed;
378
379 Resource *_res;
380};
381
385class SJISFontEoB1PC98 : public SJISFont {
386public:
387 SJISFontEoB1PC98(Common::SharedPtr<Graphics::FontSJIS> &font, /*uint8 shadowColor,*/ const uint16 *convTable1, const uint16 *convTable2);
388 ~SJISFontEoB1PC98() override {}
389 int getCharWidth(uint16 c) const override;
390 void drawChar(uint16 c, byte *dst, int pitch, int) const override;
391
392private:
393 uint16 convert(uint16 c) const;
394 const uint16 *_convTable1, *_convTable2;
395 bool _defaultConv;
396};
397
401class SJISFontEoB2PC98 : public SJISFont {
402public:
403 SJISFontEoB2PC98(Common::SharedPtr<Graphics::FontSJIS> &font, /*uint8 shadowColor,*/ const char *convTable1, const char *convTable2);
404 ~SJISFontEoB2PC98() override {}
405 int getCharWidth(uint16 c) const override;
406 void drawChar(uint16 c, byte *dst, int pitch, int) const override;
407
408private:
409 uint16 convert(uint16 c) const;
410 const char *_convTable1, *_convTable2;
411 //bool _defaultConv;
412};
413
418class Font12x12PC98 : public OldDOSFont{
419public:
420 Font12x12PC98(uint8 shadowColor, const uint16 *convTable1, const uint16 *convTable2, const uint8 *lookupTable);
421 ~Font12x12PC98() override;
422 bool usesOverlay() const override { return true; }
423 Type getType() const override { return kJIS_X0201; }
424 int getHeight() const override { return _height >> 1; }
425 int getWidth() const override { return _width >> 1; }
426 int getCharWidth(uint16 c) const override { return _width >> 1; };
427 bool load(Common::SeekableReadStream &file) override;
428
429private:
430 uint16 convert(uint16 c) const override;
431 const uint16 *_convTable1, *_convTable2;
432 uint16 *_bmpOffs;
433};
434
439class PC98Font : public OldDOSFont {
440public:
441 PC98Font(uint8 shadowColor, bool useOverlay, int scaleV, const uint8 *convTable1 = 0, const char *convTable2 = 0, const char *convTable3 = 0);
442 ~PC98Font() override {}
443 bool load(Common::SeekableReadStream &file) override;
444 int getHeight() const override { return _outputHeight; }
445 int getWidth() const override { return _outputWidth; }
446 int getCharWidth(uint16 c) const override { return _outputWidth; };
447 Type getType() const override { return _type; }
448
449private:
450 uint16 convert(uint16 c) const override;
451 uint16 makeTwoByte(uint16 c) const;
452
453 const uint8 *_convTable1;
454 const char *_convTable2, *_convTable3;
455
456 int _outputHeight;
457 int _outputWidth;
458 const Type _type;
459};
460
464class SJISFontLarge : public SJISFont {
465public:
466 SJISFontLarge(Common::SharedPtr<Graphics::FontSJIS> &font);
467 ~SJISFontLarge() override {}
468
469 int getHeight() const override;
470 int getWidth() const override;
471 int getCharWidth(uint16 c) const override;
472
473 bool usesOverlay() const override { return false; }
474 void drawChar(uint16 c, byte *dst, int pitch, int) const override;
475};
476
480class SJISFont12x12 : public Font {
481public:
482 SJISFont12x12(const uint16 *searchTable);
483 ~SJISFont12x12() override { unload(); }
484
485 bool load(Common::SeekableReadStream &file) override;
486 Type getType() const override { return kSJIS; }
487 bool usesOverlay() const override { return true; }
488 int getHeight() const override { return _height; }
489 int getWidth() const override { return _width; }
490 int getCharWidth(uint16 c) const override { return _width; }
491 void setColorMap(const uint8 *src) override { _colorMap = src; }
492 void drawChar(uint16 c, byte *dst, int pitch, int) const override;
493
494private:
495 void unload();
496
497 uint8 *_data;
499
500 const uint8 *_colorMap;
501 const int _height, _width;
502};
503
504class SegaCDFont : public Font {
505public:
506 SegaCDFont(Common::Language lang, const uint16 *convTable1, const uint16 *convTable2, const uint8 *widthTable1, const uint8 *widthTable2, const uint8 *widthTable3);
507 ~SegaCDFont() override;
508
509 bool load(Common::SeekableReadStream &file) override;
510 Type getType() const override { return _forceOneByte ? kASCII : kSJIS; }
511 int getHeight() const override { return _height; }
512 int getWidth() const override { return _width; }
513 int getCharWidth(uint16 c) const override;
514 int getCharHeight(uint16 c) const override;
515 void setStyles(int styles) override;
516 void setColorMap(const uint8 *src) override { _colorMap = src; }
517 void drawChar(uint16 c, byte *dst, int pitch, int bpp) const override { drawChar(c, dst, pitch, 0, 0); }
518 void drawChar(uint16 c, byte *dst, int pitch, int xOffs, int yOffs) const override;
519
520private:
521 const uint8 *getGlyphData(uint16 c, uint8 &charWidth, uint8 &charHeight, uint8 &pitch) const;
522
523 const uint8 *_data;
524 const uint8 *_buffer;
525 bool _forceTwoByte;
526 bool _forceOneByte;
527 Common::Language _lang;
528 uint8 _style;
529
530 const uint8 *_colorMap;
531 const int _height, _width;
532 const uint16 *_convTable1, *_convTable2;
533 const uint8 *_widthTable1, *_widthTable2, *_widthTable3;
534};
535
536} // End of namespace Kyra
537
538#endif // ENABLE_EOB
539
540#endif
Definition: hashmap.h:85
Definition: path.h:52
Definition: stream.h:385
Definition: ptr.h:572
Definition: stream.h:745
Definition: ptr.h:159
Definition: str.h:59
Definition: system.h:166
Definition: atari-screen.h:42
Language
Definition: language.h:45
RenderMode
Definition: rendermode.h:48
Type
Definition: log.h:33
T MAX(T a, T b)
Definition: util.h:66
Definition: detection.h:27
Definition: atari-screen.h:58