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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef SKY_SCREEN_H
24 #define SKY_SCREEN_H
25 
26 
27 #include "common/scummsys.h"
28 #include "sky/skydefs.h"
29 
30 class OSystem;
31 
32 namespace Common {
33 struct Rect;
34 }
35 
36 namespace Sky {
37 
38 class Disk;
39 class SkyEngine;
40 class SkyCompact;
41 struct Compact;
42 struct DataFileHeader;
43 
44 #define SCROLL_JUMP		16
45 #define VGA_COLORS		256
46 #define GAME_COLORS		240
47 
48 #define FORE 1
49 #define BACK 0
50 
51 typedef struct {
52 	uint16 yCood;
53 	Compact *compact;
54 	DataFileHeader *sprite;
55 } StSortList;
56 
57 class Screen {
58 public:
59 	Screen(OSystem *pSystem, Disk *pDisk, SkyCompact *skyCompact);
60 	~Screen();
61 	void setPalette(uint8 *pal);
62 	void setPaletteEndian(uint8 *pal);
63 	void setPalette(uint16 fileNum);
64 	void paletteFadeUp(uint8 *pal);
65 	void paletteFadeUp(uint16 fileNr);
66 
67 	void showScreen(uint16 fileNum, bool fullscreen = false);
68 	void showScreen(uint8 *pScreen, bool fullscreen = false);
69 
70 	void handleTimer();
71 	void startSequence(uint16 fileNum);
72 	void startSequenceItem(uint16 itemNum);
73 	void stopSequence();
sequenceRunning()74 	bool sequenceRunning() { return _seqInfo.running; }
75 	void processSequence();
76 	void waitForSequence();
seqFramesLeft()77 	uint32 seqFramesLeft() { return _seqInfo.framesLeft; }
giveCurrent()78 	uint8 *giveCurrent() { return _currentScreen; }
79 	void halvePalette();
80 
81 	//- regular screen.asm routines
forceRefresh()82 	void forceRefresh() { memset(_gameGrid, 0x80, GRID_X * GRID_Y); }
83 	void fnFadeUp(uint32 palNum, uint32 scroll);
84 	void fnFadeDown(uint32 scroll);
85 	void fnDrawScreen(uint32 palette, uint32 scroll);
86 	void clearScreen(bool fullscreen = false);
87 	void setFocusRectangle(const Common::Rect& rect);
88 
89 	void recreate();
90 	void flip(bool doUpdate = true);
91 
92 	void spriteEngine();
93 
94 	void paintBox(uint16 x, uint16 y);
95 	void showGrid(uint8 *gridBuf);
96 
97 private:
98 	OSystem *_system;
99 	Disk *_skyDisk;
100 	SkyCompact *_skyCompact;
101 	static uint8 _top16Colors[16 * 3];
102 	uint8 _palette[VGA_COLORS * 3];
103 	uint32 _currentPalette;
104 	uint8 _seqGrid[20 * 12];
105 
106 	void waitForTick();
107 
108 	uint8 *_gameGrid;
109 	uint8 *_currentScreen;
110 	uint8 *_scrollScreen;
111 	struct {
112 		uint32 nextFrame;
113 		uint32 framesLeft;
114 		uint8 *seqData;
115 		uint8 *seqDataPos;
116 		volatile bool running;
117 		bool runningItem; // when playing an item, don't free it afterwards.
118 	} _seqInfo;
119 
120 	//- more regular screen.asm + layer.asm routines
121 	void convertPalette(uint8 *inPal, uint8* outPal);
122 	void palette_fadedown_helper(uint8 *pal, uint num);
123 
124 	//- sprite.asm routines
125 	// fixme: get rid of these globals
126 	uint32 _sprWidth, _sprHeight, _sprX, _sprY, _maskX1, _maskX2;
127 	void doSprites(uint8 layer);
128 	void sortSprites();
129 	void drawSprite(uint8 *spriteData, Compact *sprCompact);
130 	void verticalMask();
131 	void vertMaskSub(uint16 *grid, uint32 gridOfs, uint8 *screenPtr, uint32 layerId);
132 	void vectorToGame(uint8 gridVal);
133 };
134 
135 } // End of namespace Sky
136 
137 #endif //SKYSCREEN_H
138