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
25 #include "agos/agos.h"
26 #include "agos/intern.h"
27
28 #include "graphics/surface.h"
29
30 namespace AGOS {
31
32 #ifdef ENABLE_AGOS2
doOutput(const byte * src,uint len)33 void AGOSEngine_Feeble::doOutput(const byte *src, uint len) {
34 if (_textWindow == NULL)
35 return;
36
37 while (len-- != 0 && !shouldQuit()) {
38 if (getBitFlag(93)) {
39 if (_curWindow == 3) {
40 if ((_newLines >= _textWindow->scrollY) && (_newLines < (_textWindow->scrollY + 3)))
41 sendWindow(*src);
42 if (*src == '\n') // Do two top lines of text only
43 _newLines++;
44 src++;
45 }
46 } else {
47 if (getBitFlag(94)) {
48 if (_curWindow == 3) {
49 if (_newLines == (_textWindow->scrollY + 7))
50 sendWindow(*src);
51 if (*src == '\n') // Do two top lines of text only
52 _newLines++;
53 src++;
54 }
55 } else {
56 if (getBitFlag(92))
57 delay(50);
58 sendWindow(*src++);
59 }
60 }
61 }
62 }
63 #endif
64
doOutput(const byte * src,uint len)65 void AGOSEngine::doOutput(const byte *src, uint len) {
66 uint idx;
67
68 if (_textWindow == NULL)
69 return;
70
71 while (len-- != 0) {
72 if (*src != 12 && _textWindow->iconPtr != NULL &&
73 _fcsData1[idx = getWindowNum(_textWindow)] != 2) {
74
75 _fcsData1[idx] = 2;
76 _fcsData2[idx] = 1;
77 }
78
79 sendWindow(*src++);
80 }
81 }
82
clsCheck(WindowBlock * window)83 void AGOSEngine::clsCheck(WindowBlock *window) {
84 uint index = getWindowNum(window);
85 tidyIconArray(index);
86 _fcsData1[index] = 0;
87 }
88
tidyIconArray(uint i)89 void AGOSEngine::tidyIconArray(uint i) {
90 WindowBlock *window;
91
92 if (_fcsData2[i]) {
93 mouseOff();
94 window = _windowArray[i];
95 drawIconArray(i, window->iconPtr->itemRef, window->iconPtr->line, window->iconPtr->classMask);
96 _fcsData2[i] = 0;
97 mouseOn();
98 }
99 }
100
showMessageFormat(const char * s,...)101 void AGOSEngine::showMessageFormat(const char *s, ...) {
102 char buf[STRINGBUFLEN];
103 char *str;
104 va_list va;
105
106 va_start(va, s);
107 vsnprintf(buf, STRINGBUFLEN, s, va);
108 va_end(va);
109
110 if (!_fcsData1[_curWindow]) {
111 if (getGameType() == GType_ELVIRA1 || getGameType() == GType_ELVIRA2 || getGameType() == GType_WW) {
112 if (_showMessageFlag) {
113 if (_windowArray[_curWindow]->flags & 128) {
114 haltAnimation();
115 }
116 }
117 }
118 openTextWindow();
119 if (!_showMessageFlag) {
120 _windowArray[0] = _textWindow;
121 justifyStart();
122 }
123 _showMessageFlag = true;
124 _fcsData1[_curWindow] = 1;
125 }
126
127 for (str = buf; *str; str++)
128 justifyOutPut(*str);
129 }
130
justifyStart()131 void AGOSEngine::justifyStart() {
132 if (getGameType() == GType_FF || getGameType() == GType_PP) {
133 _printCharCurPos = _textWindow->textColumn;
134 _printCharMaxPos = _textWindow->width;
135 } else {
136 _printCharCurPos = _textWindow->textLength;
137 _printCharMaxPos = _textWindow->textMaxLength;
138 }
139 _printCharPixelCount = 0;
140 _numLettersToPrint = 0;
141 _newLines = 0;
142 }
143
justifyOutPut(byte chr)144 void AGOSEngine::justifyOutPut(byte chr) {
145 if (chr == 12) {
146 _numLettersToPrint = 0;
147 _printCharCurPos = 0;
148 _printCharPixelCount = 0;
149 doOutput(&chr, 1);
150 clsCheck(_textWindow);
151 } else if (chr == 0 || chr == ' ' || chr == 10) {
152 bool fit;
153
154 if (getGameType() == GType_FF || getGameType() == GType_PP) {
155 fit = _printCharMaxPos - _printCharCurPos > _printCharPixelCount;
156 } else {
157 fit = _printCharMaxPos - _printCharCurPos >= _printCharPixelCount;
158 }
159
160 if (fit) {
161 _printCharCurPos += _printCharPixelCount;
162 doOutput(_lettersToPrintBuf, _numLettersToPrint);
163
164 if (_printCharCurPos == _printCharMaxPos) {
165 _printCharCurPos = 0;
166 } else {
167 if (chr)
168 doOutput(&chr, 1);
169 if (chr == 10)
170 _printCharCurPos = 0;
171 else if (chr != 0)
172 _printCharCurPos += (getGameType() == GType_FF || getGameType() == GType_PP) ? getFeebleFontSize(chr) : 1;
173 }
174 } else {
175 const byte newline_character = 10;
176 _printCharCurPos = _printCharPixelCount;
177 doOutput(&newline_character, 1);
178 doOutput(_lettersToPrintBuf, _numLettersToPrint);
179 if (chr == ' ') {
180 doOutput(&chr, 1);
181 _printCharCurPos += (getGameType() == GType_FF || getGameType() == GType_PP) ? getFeebleFontSize(chr) : 1;
182 } else {
183 doOutput(&chr, 1);
184 _printCharCurPos = 0;
185 }
186 }
187 _numLettersToPrint = 0;
188 _printCharPixelCount = 0;
189 } else {
190 _lettersToPrintBuf[_numLettersToPrint++] = chr;
191 _printCharPixelCount += (getGameType() == GType_FF || getGameType() == GType_PP) ? getFeebleFontSize(chr) : 1;
192 }
193 }
194
openTextWindow()195 void AGOSEngine::openTextWindow() {
196 if (_textWindow) {
197 if (getGameType() == GType_ELVIRA1 || getGameType() == GType_ELVIRA2 || getGameType() == GType_WW) {
198 if (_textWindow->flags & 0x80)
199 clearWindow(_textWindow);
200 }
201 return;
202 }
203
204 if (getGameType() == GType_FF || getGameType() == GType_PP)
205 _textWindow = openWindow(64, 96, 384, 172, 1, 0, 15);
206 else
207 _textWindow = openWindow(8, 144, 24, 6, 1, 0, 15);
208 }
209
windowPutChar(WindowBlock * window,byte c,byte b)210 void AGOSEngine_PN::windowPutChar(WindowBlock *window, byte c, byte b) {
211 if (_mousePrintFG || _wiped)
212 return;
213 AGOSEngine::windowPutChar(window, c, b);
214 }
215
windowPutChar(WindowBlock * window,byte c,byte b)216 void AGOSEngine::windowPutChar(WindowBlock *window, byte c, byte b) {
217 byte width = 6;
218
219 if (c == 12) {
220 clearWindow(window);
221 } else if (c == 13 || c == 10) {
222 windowNewLine(window);
223 } else if ((c == 1 && _language != Common::HE_ISR) || (c == 8)) {
224 if (_language == Common::HE_ISR) {
225 if (b >= 64 && b < 91)
226 width = _hebrewCharWidths [b - 64];
227
228 if (window->textLength != 0) {
229 window->textLength--;
230 window->textColumnOffset += width;
231 if (window->textColumnOffset >= 8) {
232 window->textColumnOffset -= 8;
233 window->textColumn--;
234 }
235 }
236 } else {
237 int8 val = (c == 8) ? 6 : 4;
238
239 if (window->textLength != 0) {
240 window->textLength--;
241 window->textColumnOffset -= val;
242 if ((int8)window->textColumnOffset < val) {
243 window->textColumnOffset += 8;
244 window->textColumn--;
245 }
246 }
247 }
248 } else if (c >= 32) {
249 if (getGameType() == GType_FF || getGameType() == GType_PP) {
250 // Ignore invalid characters
251 if (c - 32 > 195)
252 return;
253
254 windowDrawChar(window, window->textColumn + window->x, window->textRow + window->y, c);
255 window->textColumn += getFeebleFontSize(c);
256 return;
257 }
258
259 // Ignore invalid characters
260 if (c - 32 > 98)
261 return;
262
263 if (window->textLength == window->textMaxLength) {
264 windowNewLine(window);
265 } else if (window->textRow == window->height) {
266 windowNewLine(window);
267 window->textRow--;
268 }
269
270 if (_language == Common::HE_ISR) {
271 if (c >= 64 && c < 91)
272 width = _hebrewCharWidths [c - 64];
273 window->textColumnOffset -= width;
274 if (window->textColumnOffset >= width) {
275 window->textColumnOffset += 8;
276 window->textColumn++;
277 }
278 windowDrawChar(window, (window->width + window->x - window->textColumn) * 8, window->textRow * 8 + window->y, c);
279 window->textLength++;
280 } else {
281 windowDrawChar(window, (window->textColumn + window->x) * 8, window->textRow * 8 + window->y, c);
282
283 window->textLength++;
284 window->textColumnOffset += 6;
285 if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) {
286 if (c == 'i' || c == 'l')
287 window->textColumnOffset -= 2;
288 }
289 if (window->textColumnOffset >= 8) {
290 window->textColumnOffset -= 8;
291 window->textColumn++;
292 }
293 }
294 }
295 }
296
297 #ifdef ENABLE_AGOS2
windowNewLine(WindowBlock * window)298 void AGOSEngine_Feeble::windowNewLine(WindowBlock *window) {
299 if (_noOracleScroll == 0) {
300 if (window->height < window->textRow + 30) {
301 if (!getBitFlag(94)) {
302 _noOracleScroll = 1;
303 if (getBitFlag(92)) {
304 _noOracleScroll = 0;
305 checkLinkBox();
306 scrollOracle();
307 linksUp();
308 window->scrollY++;
309 _oracleMaxScrollY++;
310 } else {
311 _oracleMaxScrollY++;
312 checkLinkBox();
313 }
314 }
315 } else {
316 window->textRow += 15;
317 checkLinkBox();
318 }
319 } else {
320 _oracleMaxScrollY++;
321 checkLinkBox();
322 }
323
324 window->textColumn = 0;
325 window->textColumnOffset = 0;
326 window->textLength = 0;
327 }
328 #endif
329
windowNewLine(WindowBlock * window)330 void AGOSEngine::windowNewLine(WindowBlock *window) {
331 window->textColumn = 0;
332 window->textColumnOffset = (getGameType() == GType_ELVIRA2) ? 4 : 0;
333 window->textLength = 0;
334
335 if (getGameType() == GType_PN) {
336 window->textRow++;
337 if (window->textRow == window->height) {
338 windowScroll(window);
339 window->textRow--;
340 }
341 } else {
342 if (window->textRow == window->height) {
343 if (getGameType() == GType_ELVIRA1 || getGameType() == GType_ELVIRA2 ||
344 getGameType() == GType_WW) {
345 windowScroll(window);
346 }
347 } else {
348 window->textRow++;
349 }
350 }
351 }
352
windowScroll(WindowBlock * window)353 void AGOSEngine::windowScroll(WindowBlock *window) {
354 _videoLockOut |= 0x8000;
355
356 if (window->height != 1) {
357 Graphics::Surface *screen = _system->lockScreen();
358
359 byte *src, *dst;
360 uint16 w, h;
361
362 w = window->width * 8;
363 h = (window->height -1) * 8;
364
365 dst = (byte *)screen->getBasePtr(window->x * 8, window->y);
366 src = dst + 8 * screen->pitch;
367
368 do {
369 memcpy(dst, src, w);
370 src += screen->pitch;
371 dst += screen->pitch;
372 } while (--h);
373
374 _system->unlockScreen();
375 }
376
377 colorBlock(window, window->x * 8, (window->height - 1) * 8 + window->y, window->width * 8, 8);
378
379 _videoLockOut &= ~0x8000;
380 }
381 } // End of namespace AGOS
382