aboutsummaryrefslogtreecommitdiff
path: root/engines/dreamweb/print.cpp
blob: 64b98499801d243477fd4f15dde4d8e669d590ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"

namespace DreamWeb {

void DreamWebEngine::printBoth(const GraphicsFile &charSet, uint16 *x, uint16 y, uint8 c, uint8 nextChar) {
	uint16 newX = *x;
	uint8 width, height;
	printChar(charSet, &newX, y, c, nextChar, &width, &height);
	multiDump(*x, y, width, height);
	*x = newX;
}

uint8 DreamWebEngine::getNextWord(const GraphicsFile &charSet, const uint8 *string, uint8 *totalWidth, uint8 *charCount) {
	*totalWidth = 0;
	*charCount = 0;
	while (true) {
		uint8 firstChar = *string;
		++string;
		++*charCount;
		if ((firstChar == ':') || (firstChar == 0)) { //endall
			*totalWidth += 6;
			return 1;
		}
		if (firstChar == 32) { //endword
			*totalWidth += 6;
			return 0;
		}
		firstChar = modifyChar(firstChar);
		if (firstChar != 255) {
			uint8 secondChar = *string;
			uint8 width = charSet._frames[firstChar - 32 + _charShift].width;
			width = kernChars(firstChar, secondChar, width);
			*totalWidth += width;
		}
	}
}

void DreamWebEngine::printChar(const GraphicsFile &charSet, uint16* x, uint16 y, uint8 c, uint8 nextChar, uint8 *width, uint8 *height) {
	if (c == 255)
		return;

	uint8 dummyWidth, dummyHeight;
	if (width == NULL)
		width = &dummyWidth;
	if (height == NULL)
		height = &dummyHeight;
	if (_foreignRelease)
		y -= 3;
	uint16 tmp = c - 32 + _charShift;
	showFrame(charSet, *x, y, tmp & 0x1ff, (tmp >> 8) & 0xfe, width, height);
	if (_kerning == 0)
		*width = kernChars(c, nextChar, *width);
	(*x) += *width;
}

void DreamWebEngine::printChar(const GraphicsFile &charSet, uint16 x, uint16 y, uint8 c, uint8 nextChar, uint8 *width, uint8 *height) {
	printChar(charSet, &x, y, c, nextChar, width, height);
}

uint8 DreamWebEngine::printSlow(const uint8 *string, uint16 x, uint16 y, uint8 maxWidth, bool centered) {
	_pointerFrame = 1;
	_pointerMode = 3;
	do {
		uint16 offset = x;
		uint16 charCount = getNumber(_charset1, string, maxWidth, centered, &offset);
		do {
			uint8 c0 = string[0];
			uint8 c1 = string[1];
			uint8 c2 = string[2];
			c0 = modifyChar(c0);
			printBoth(_charset1, &offset, y, c0, c1);
			if ((c1 == 0) || (c1 == ':')) {
				return 0;
			}
			if (charCount != 1) {
				c1 = modifyChar(c1);
				_charShift = 91;
				uint16 offset2 = offset;
				printBoth(_charset1, &offset2, y, c1, c2);
				_charShift = 0;
				for (int i=0; i<2; ++i) {
					uint16 mouseState = waitFrames();
					if (_quitRequested)
						return 0;
					if (mouseState == 0)
						continue;
					if (mouseState != _oldButton) {
						return 1;
					}
				}
			}

			++string;
			--charCount;
		} while (charCount);
		y += 10;
	} while (true);
}

uint8 DreamWebEngine::printDirect(const uint8* string, uint16 x, uint16 y, uint8 maxWidth, bool centered) {
	return printDirect(&string, x, &y, maxWidth, centered);
}

uint8 DreamWebEngine::printDirect(const uint8** string, uint16 x, uint16 *y, uint8 maxWidth, bool centered) {
	_lastXPos = x;
	const GraphicsFile &charSet = *_currentCharset;
	while (true) {
		uint16 offset = x;
		uint8 charCount = getNumber(charSet, *string, maxWidth, centered, &offset);
		uint16 i = offset;
		do {
			uint8 c = (*string)[0];
			uint8 nextChar = (*string)[1];
			++(*string);
			if ((c == 0) || (c == ':')) {
				return c;
			}
			c = modifyChar(c);
			uint8 width, height;
			printChar(charSet, &i, *y, c, nextChar, &width, &height);
			_lastXPos = i;
			--charCount;
		} while (charCount);
		*y += _lineSpacing;
	}
}

uint8 DreamWebEngine::getNumber(const GraphicsFile &charSet, const uint8 *string, uint16 maxWidth, bool centered, uint16* offset) {
	uint8 totalWidth = 0;
	uint8 charCount = 0;
	while (true) {
		uint8 wordTotalWidth, wordCharCount;
		uint8 done = getNextWord(charSet, string, &wordTotalWidth, &wordCharCount);
		string += wordCharCount;

		uint16 tmp = totalWidth + wordTotalWidth - 10;
		if (done == 1) { //endoftext
			if (tmp < maxWidth) {
				totalWidth += wordTotalWidth;
				charCount += wordCharCount;
			}

			if (centered) {
				tmp = (maxWidth & 0xfe) + 2 + 20 - totalWidth;
				tmp /= 2;
			} else {
				tmp = 0;
			}
			*offset += tmp;
			return charCount;
		}
		if (tmp >= maxWidth) { //gotoverend
			if (centered) {
				tmp = (maxWidth & 0xfe) - totalWidth + 20;
				tmp /= 2;
			} else {
				tmp = 0;
			}
			*offset += tmp;
			return charCount;
		}
		totalWidth += wordTotalWidth;
		charCount += wordCharCount;
	}
}

uint8 DreamWebEngine::kernChars(uint8 firstChar, uint8 secondChar, uint8 width) {
	if ((firstChar == 'a') || (firstChar == 'u')) {
		if ((secondChar == 'n') || (secondChar == 't') || (secondChar == 'r') || (secondChar == 'i') || (secondChar == 'l'))
			return width-1;
	}
	return width;
}

uint16 DreamWebEngine::waitFrames() {
	readMouse();
	showPointer();
	waitForVSync();
	dumpPointer();
	delPointer();
	return _mouseButton;
}

const char *DreamWebEngine::monPrint(const char *string) {
	_kerning = 1;
	uint16 x = _monAdX;
	const char *iterator = string;
	bool done = false;
	while (!done) {

		uint16 count = getNumber(_monitorCharset, (const uint8 *)iterator, 166, false, &x);
		do {
			char c = *iterator++;
			if (c == ':')
				break;
			if ((c == 0) || (c == '"') || (c == '=')) {
				done = true;
				break;
			}
			if (c == '%') {
				_vars._lastTrigger = *iterator;
				iterator += 2;
				done = true;
				break;
			}
			c = modifyChar(c);
			printChar(_monitorCharset, &x, _monAdY, c, 0, NULL, NULL);
			_cursLocX = x;
			_cursLocY = _monAdY;
			_mainTimer = 1;
			printCurs();
			waitForVSync();
			lockMon();
			delCurs();
		} while (--count);

		x = _monAdX;
		scrollMonitor();
		_cursLocX = _monAdX;
	}

	_kerning = 0;
	return iterator;
}

void DreamWebEngine::rollEndCreditsGameWon() {
	_sound->playChannel0(16, 255);
	_sound->volumeSet(7);
	_sound->volumeChange(0, -1);

	multiGet(_mapStore, 75, 20, 160, 160);

	const uint8 *string = getTextInFile1(3);
	const int linespacing = _lineSpacing;

	for (int i = 0; i < 254; ++i) {
		// Output the text, initially with an offset of 10 pixels,
		// then move it up one pixel until we shifted it by a complete
		// line of text.
		for (int j = 0; j < linespacing; ++j) {
			waitForVSync();
			multiPut(_mapStore, 75, 20, 160, 160);
			waitForVSync();

			// Output up to 18 lines of text
			uint16 y = 10 - j;
			const uint8 *tmp_str = string;
			for (int k = 0; k < 18; ++k) {
				printDirect(&tmp_str, 75, &y, 160 + 1, true);
				y += linespacing;
			}

			waitForVSync();
			multiDump(75, 20, 160, 160);
		}

		// Skip to the next text line
		byte c;
		do {
			c = *string++;
		} while (c != ':' && c != 0);
	}

	hangOn(100);
	panelToMap();
	fadeScreenUpHalf();
}

void DreamWebEngine::rollEndCreditsGameLost() {
	multiGet(_mapStore, 25, 20, 160, 160);

	const uint8 *string = getTextInFile1(49);
	const int linespacing = _lineSpacing;

	for (int i = 0; i < 80; ++i) {
		// Output the text, initially with an offset of 10 pixels,
		// then move it up one pixel until we shifted it by a complete
		// line of text.
		for (int j = 0; j < linespacing; ++j) {
			waitForVSync();
			multiPut(_mapStore, 25, 20, 160, 160);
			waitForVSync();

			// Output up to 18 lines of text
			uint16 y = 10 - j;
			const uint8 *tmp_str = string;
			for (int k = 0; k < 18; ++k) {
				printDirect(&tmp_str, 25, &y, 160 + 1, true);
				y += linespacing;
			}

			waitForVSync();
			multiDump(25, 20, 160, 160);

			if (_lastHardKey == 1)
				return;
		}

		// Skip to the next text line
		byte c;
		do {
			c = *string++;
		} while (c != ':' && c != 0);

		if (_lastHardKey == 1)
			return;
	}

	hangOne(120);
}

} // End of namespace DreamWeb