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 #include "common/system.h"
24 #include "graphics/macega.h"
25 #include "scumm/actor.h"
26 #include "scumm/charset.h"
27 #include "scumm/usage_bits.h"
28 #include "scumm/verbs.h"
29 
30 namespace Scumm {
31 
mac_drawStripToScreen(VirtScreen * vs,int top,int x,int y,int width,int height)32 void ScummEngine::mac_drawStripToScreen(VirtScreen *vs, int top, int x, int y, int width, int height) {
33 
34 	const byte *pixels = vs->getPixels(x, top);
35 	const byte *ts = (byte *)_textSurface.getBasePtr(x * 2, y * 2);
36 	byte *mac = (byte *)_macScreen->getBasePtr(x * 2, y * 2);
37 
38 	int pixelsPitch = vs->pitch;
39 	int tsPitch = _textSurface.pitch;
40 	int macPitch = _macScreen->pitch;
41 
42 	// In b/w Mac rendering mode, the shadow palette is implemented here,
43 	// and not as a palette manipulation. See special cases in o5_roomOps()
44 	// and updatePalette().
45 	//
46 	// This is used at the very least for the lightning flashes at Castle
47 	// Brunwald in Indy 3, as well as the scene where the dragon finds
48 	// Rusty in Loom.
49 	//
50 	// Interestingly, the original Mac interpreter does not seem to do
51 	// this, and instead just renders the scene as if the palette was
52 	// unmodified. At least, that's what Mini vMac did when I tried it.
53 
54 	if (_renderMode == Common::kRenderMacintoshBW) {
55 		for (int h = 0; h < height; h++) {
56 			for (int w = 0; w < width; w++) {
57 				int color = _shadowPalette[pixels[w]];
58 				if (ts[2 * w] == CHARSET_MASK_TRANSPARENCY)
59 					mac[2 * w] = Graphics::macEGADither[color][0];
60 				if (ts[2 * w + 1] == CHARSET_MASK_TRANSPARENCY)
61 					mac[2 * w + 1] = Graphics::macEGADither[color][1];
62 				if (ts[2 * w + tsPitch] == CHARSET_MASK_TRANSPARENCY)
63 					mac[2 * w + macPitch] = Graphics::macEGADither[color][2];
64 				if (ts[2 * w + tsPitch + 1] == CHARSET_MASK_TRANSPARENCY)
65 					mac[2 * w + macPitch + 1] = Graphics::macEGADither[color][3];
66 			}
67 
68 			pixels += pixelsPitch;
69 			ts += tsPitch * 2;
70 			mac += macPitch * 2;
71 		}
72 	} else {
73 		for (int h = 0; h < height; h++) {
74 			for (int w = 0; w < width; w++) {
75 				if (ts[2 * w] == CHARSET_MASK_TRANSPARENCY)
76 					mac[2 * w] = pixels[w];
77 				if (ts[2 * w + 1] == CHARSET_MASK_TRANSPARENCY)
78 					mac[2 * w + 1] = pixels[w];
79 				if (ts[2 * w + tsPitch] == CHARSET_MASK_TRANSPARENCY)
80 					mac[2 * w + macPitch] = pixels[w];
81 				if (ts[2 * w + tsPitch + 1] == CHARSET_MASK_TRANSPARENCY)
82 					mac[2 * w + macPitch + 1] = pixels[w];
83 			}
84 
85 			pixels += pixelsPitch;
86 			ts += tsPitch * 2;
87 			mac += macPitch * 2;
88 		}
89 	}
90 
91 
92 	_system->copyRectToScreen(_macScreen->getBasePtr(x * 2, y * 2), _macScreen->pitch, x * 2, y * 2, width * 2, height * 2);
93 }
94 
mac_drawLoomPracticeMode()95 void ScummEngine::mac_drawLoomPracticeMode() {
96 	// In practice mode, the game shows the notes as they are being played.
97 	// In the DOS version, this is drawn by script 27 but the Mac version
98 	// just sets variables 50 and 54. The box is actually a verb, and it
99 	// seems that setting variable 50 is pretty much equal to turning verb
100 	// 53 on or off. I'm not sure what the purpose of variable 54 is.
101 
102 	int x = 216;
103 	int y = 377;
104 	int width = 62;
105 	int height = 22;
106 	int var = 50;
107 
108 	byte *ptr = (byte *)_macScreen->getBasePtr(x,  y);
109 	int pitch = _macScreen->pitch;
110 
111 	int slot = getVerbSlot(53, 0);
112 	VerbSlot *vs = &_verbs[slot];
113 
114 	vs->curmode = (VAR(var) != 0);
115 	vs->curRect.left = x / 2;
116 	vs->curRect.right = (x + width) / 2;
117 	vs->curRect.top = y / 22;
118 	vs->curRect.bottom = (y + height) / 2;
119 
120 	_macScreen->fillRect(Common::Rect(x, y, x + width, y + height), 0);
121 
122 	if (VAR(var)) {
123 		for (int w = 1; w < width - 1; w++) {
124 			ptr[w] = 7;
125 			ptr[w + pitch * (height - 1)] = 7;
126 		}
127 
128 		for (int h = 1; h < height - 1; h++) {
129 			ptr[h * pitch] = 7;
130 			ptr[h * pitch + width - 1] = 7;
131 		}
132 
133 		// Draw the notes
134 		int colors[] = { 4, 12, 14, 10, 11, 3, 9, 15 };
135 
136 		for (int i = 0; i < 4; i++) {
137 			int note = (VAR(var) >> (4 * i)) & 0x0F;
138 
139 			if (note >= 2 && note <= 9) {
140 				_charset->setColor(colors[note - 2]);
141 				_charset->drawChar(14 + note, *_macScreen, i * 13 + x + 8, y + 4);
142 			}
143 		}
144 	}
145 
146 	_system->copyRectToScreen(ptr, pitch, x, y, width, height);
147 }
148 
mac_createIndy3TextBox(Actor * a)149 void ScummEngine::mac_createIndy3TextBox(Actor *a) {
150 	int width = _macIndy3TextBox->w;
151 	int height = _macIndy3TextBox->h;
152 
153 	_macIndy3TextBox->fillRect(Common::Rect(width, height), 0);
154 
155 	int nameWidth = 0;
156 
157 	if (a) {
158 		int oldID = _charset->getCurID();
159 		_charset->setCurID(2);
160 
161 		const char *name = (const char *)a->getActorName();
162 		int charX = 25;
163 
164 		for (int i = 0; name[i] && nameWidth < width - 50; i++) {
165 			_charset->drawChar(name[i], *_macIndy3TextBox, charX, 0);
166 			nameWidth += _charset->getCharWidth(name[i]);
167 			charX += _charset->getCharWidth(name[i]);
168 		}
169 
170 		_charset->drawChar(':', *_macIndy3TextBox, charX, 0);
171 		_charset->setCurID(oldID);
172 	}
173 
174 	if (nameWidth) {
175 		_macIndy3TextBox->hLine(2, 3, 20, 15);
176 		_macIndy3TextBox->hLine(32 + nameWidth, 3, width - 3, 15);
177 	} else
178 		_macIndy3TextBox->hLine(2, 3, width - 3, 15);
179 
180 	_macIndy3TextBox->vLine(1, 4, height - 3, 15);
181 	_macIndy3TextBox->vLine(width - 2, 4, height - 3, 15);
182 	_macIndy3TextBox->hLine(2, height - 2, width - 3, 15);
183 }
184 
mac_drawIndy3TextBox()185 void ScummEngine::mac_drawIndy3TextBox() {
186 	// The first two rows of the text box are padding for font rendering.
187 	// They are not drawn to the screen.
188 
189 	int x = 96;
190 	int y = 32;
191 	int w = _macIndy3TextBox->w;
192 	int h = _macIndy3TextBox->h - 2;
193 
194 	// The text box is drawn to the Mac screen and text surface, as if it
195 	// had been one giant glyph. Note that it will be drawn on the main
196 	// virtual screen, but we still pretend it's on the text one.
197 
198 	VirtScreen *vs = &_virtscr[kMainVirtScreen];
199 
200 	byte *ptr = (byte *)_macIndy3TextBox->getBasePtr(0, 2);
201 	int pitch = _macIndy3TextBox->pitch;
202 
203 	_macScreen->copyRectToSurface(ptr, pitch, x, y, w, h);
204 	_textSurface.fillRect(Common::Rect(x, y, x + w, y + h), 0);
205 
206 	// Mark the virtual screen as dirty. The top and left coordinates are
207 	// rounded down, while the bottom and right ones are rounded up.
208 
209 	int vsTop = y / 2 - vs->topline;
210 	int vsBottom = (y + h) / 2 - vs->topline;
211 	int vsLeft = x / 2;
212 	int vsRight = (x + w) / 2;
213 
214 	if ((y + h) & 1)
215 		vsBottom++;
216 
217 	if ((x + w) & 1)
218 		vsRight++;
219 
220 	markRectAsDirty(kMainVirtScreen, vsLeft, vsRight, vsTop, vsBottom);
221 }
222 
mac_undrawIndy3TextBox()223 void ScummEngine::mac_undrawIndy3TextBox() {
224 	int x = 96;
225 	int y = 32;
226 	int w = _macIndy3TextBox->w;
227 	int h = _macIndy3TextBox->h - 2;
228 
229 	_macScreen->fillRect(Common::Rect(x, y, x + w, y + h), 0);
230 	_textSurface.fillRect(Common::Rect(x, y, x + w, y + h), CHARSET_MASK_TRANSPARENCY);
231 
232 	VirtScreen *vs = &_virtscr[kMainVirtScreen];
233 
234 	int vsTop = y / 2 - vs->topline;
235 	int vsBottom = (y + h) / 2 - vs->topline;
236 	int vsLeft = x / 2;
237 	int vsRight = (x + w) / 2;
238 
239 	if ((y + h) & 1)
240 		vsBottom++;
241 
242 	if ((x + w) & 1)
243 		vsRight++;
244 
245 	markRectAsDirty(kMainVirtScreen, vsLeft, vsRight, vsTop, vsBottom);
246 }
247 
mac_undrawIndy3CreditsText()248 void ScummEngine::mac_undrawIndy3CreditsText() {
249 	if (_macScreen) {
250 		// Set _masMask to make the text clear, and _textScreenID to
251 		// ensure that it's the main area that's cleared. Note that
252 		// this only works with the high-resolution font.
253 		_charset->_hasMask = true;
254 		_charset->_textScreenID = kMainVirtScreen;
255 		restoreCharsetBg();
256 	} else {
257 		// The DOS VGA version clear the text by using the putState
258 		// opcode. I would have been more comfortable if I could have
259 		// compared it to the EGA version, but I don't have that.
260 		// Judging by the size and position of the object, they should
261 		// be the same.
262 		putState(946, 0);
263 		markObjectRectAsDirty(946);
264 		if (_bgNeedsRedraw)
265 			clearDrawObjectQueue();
266 	}
267 }
268 
269 } // End of namespace Scumm
270