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 "dreamweb/sound.h"
24 #include "dreamweb/dreamweb.h"
25 
26 namespace DreamWeb {
27 
28 const uint16 kKeypadx = 36+112;
29 const uint16 kKeypady = 72;
30 
enterCode(uint8 digit0,uint8 digit1,uint8 digit2,uint8 digit3)31 void DreamWebEngine::enterCode(uint8 digit0, uint8 digit1, uint8 digit2, uint8 digit3) {
32 	RectWithCallback keypadList[] = {
33 		{ kKeypadx+9,kKeypadx+30,kKeypady+9,kKeypady+22,&DreamWebEngine::buttonOne },
34 		{ kKeypadx+31,kKeypadx+52,kKeypady+9,kKeypady+22,&DreamWebEngine::buttonTwo },
35 		{ kKeypadx+53,kKeypadx+74,kKeypady+9,kKeypady+22,&DreamWebEngine::buttonThree },
36 		{ kKeypadx+9,kKeypadx+30,kKeypady+23,kKeypady+40,&DreamWebEngine::buttonFour },
37 		{ kKeypadx+31,kKeypadx+52,kKeypady+23,kKeypady+40,&DreamWebEngine::buttonFive },
38 		{ kKeypadx+53,kKeypadx+74,kKeypady+23,kKeypady+40,&DreamWebEngine::buttonSix },
39 		{ kKeypadx+9,kKeypadx+30,kKeypady+41,kKeypady+58,&DreamWebEngine::buttonSeven },
40 		{ kKeypadx+31,kKeypadx+52,kKeypady+41,kKeypady+58,&DreamWebEngine::buttonEight },
41 		{ kKeypadx+53,kKeypadx+74,kKeypady+41,kKeypady+58,&DreamWebEngine::buttonNine },
42 		{ kKeypadx+9,kKeypadx+30,kKeypady+59,kKeypady+73,&DreamWebEngine::buttonNought },
43 		{ kKeypadx+31,kKeypadx+74,kKeypady+59,kKeypady+73,&DreamWebEngine::buttonEnter },
44 		{ kKeypadx+72,kKeypadx+86,kKeypady+80,kKeypady+94,&DreamWebEngine::quitKey },
45 		{ 0,320,0,200,&DreamWebEngine::blank },
46 		{ 0xFFFF,0,0,0,0 }
47 	};
48 
49 	getRidOfReels();
50 	loadKeypad();
51 	createPanel();
52 	showIcon();
53 	showOuterPad();
54 	showKeypad();
55 	readMouse();
56 	showPointer();
57 	workToScreen();
58 	delPointer();
59 	_pressPointer = 0;
60 	_getBack = 0;
61 	while (true) {
62 		delPointer();
63 		readMouse();
64 		showKeypad();
65 		showPointer();
66 		waitForVSync();
67 		if (_pressCount == 0) {
68 			_pressed = 255;
69 			_graphicPress = 255;
70 			waitForVSync();
71 		} else
72 			--_pressCount;
73 
74 		dumpPointer();
75 		dumpKeypad();
76 		dumpTextLine();
77 		checkCoords(keypadList);
78 		if (_quitRequested || (_getBack == 1))
79 			break;
80 		if (_lightCount == 1) {
81 			if (_vars._lockStatus == 0)
82 				break;
83 		} else {
84 			if (_pressCount == 40) {
85 				addToPressList();
86 				if (_pressed == 11) {
87 					if (isItRight(digit0, digit1, digit2, digit3))
88 						_vars._lockStatus = 0;
89 					_sound->playChannel1(11);
90 					_lightCount = 120;
91 					_pressPointer = 0;
92 				}
93 			}
94 		}
95 	}
96 	_manIsOffScreen = 0;
97 	_keypadGraphics.clear();
98 	restoreReels();
99 	redrawMainScrn();
100 	workToScreenM();
101 }
102 
103 // Note: isItRight comes from use.asm, but is only used by enterCode(),
104 // so we place it here.
isItRight(uint8 digit0,uint8 digit1,uint8 digit2,uint8 digit3)105 bool DreamWebEngine::isItRight(uint8 digit0, uint8 digit1, uint8 digit2, uint8 digit3) {
106 	return digit0 == _pressList[0] && digit1 == _pressList[1]
107 		&& digit2 == _pressList[2] && digit3 == _pressList[3];
108 }
109 
loadKeypad()110 void DreamWebEngine::loadKeypad() {
111 	loadGraphicsFile(_keypadGraphics, "G02");
112 }
113 
quitKey()114 void DreamWebEngine::quitKey() {
115 	commandOnlyCond(4, 222);
116 
117 	if (_mouseButton != _oldButton && (_mouseButton & 1))
118 		_getBack = 1;
119 }
120 
addToPressList()121 void DreamWebEngine::addToPressList() {
122 	if (_pressPointer == 5)
123 		return;
124 	uint8 pressed = _pressed;
125 	if (pressed == 10)
126 		pressed = 0;
127 
128 	_pressList[_pressPointer] = pressed;
129 	++_pressPointer;
130 }
131 
buttonOne()132 void DreamWebEngine::buttonOne() {
133 	buttonPress(1);
134 }
135 
buttonTwo()136 void DreamWebEngine::buttonTwo() {
137 	buttonPress(2);
138 }
139 
buttonThree()140 void DreamWebEngine::buttonThree() {
141 	buttonPress(3);
142 }
143 
buttonFour()144 void DreamWebEngine::buttonFour() {
145 	buttonPress(4);
146 }
147 
buttonFive()148 void DreamWebEngine::buttonFive() {
149 	buttonPress(5);
150 }
151 
buttonSix()152 void DreamWebEngine::buttonSix() {
153 	buttonPress(6);
154 }
155 
buttonSeven()156 void DreamWebEngine::buttonSeven() {
157 	buttonPress(7);
158 }
159 
buttonEight()160 void DreamWebEngine::buttonEight() {
161 	buttonPress(8);
162 }
163 
buttonNine()164 void DreamWebEngine::buttonNine() {
165 	buttonPress(9);
166 }
167 
buttonNought()168 void DreamWebEngine::buttonNought() {
169 	buttonPress(10);
170 }
171 
buttonEnter()172 void DreamWebEngine::buttonEnter() {
173 	buttonPress(11);
174 }
175 
buttonPress(uint8 buttonId)176 void DreamWebEngine::buttonPress(uint8 buttonId) {
177 	commandOnlyCond(buttonId + 4, buttonId + 100);
178 	if ((_mouseButton & 1) && (_mouseButton != _oldButton)) {
179 		_pressed = buttonId;
180 		_graphicPress = buttonId + 21;
181 		_pressCount = 40;
182 		if (buttonId != 11)
183 			_sound->playChannel1(10);
184 	}
185 }
186 
showOuterPad()187 void DreamWebEngine::showOuterPad() {
188 	showFrame(_keypadGraphics, kKeypadx-3, kKeypady-4, 1, 0);
189 	showFrame(_keypadGraphics, kKeypadx+74, kKeypady+76, 37, 0);
190 }
191 
showKeypad()192 void DreamWebEngine::showKeypad() {
193 	singleKey(22, kKeypadx+9,  kKeypady+5);
194 	singleKey(23, kKeypadx+31, kKeypady+5);
195 	singleKey(24, kKeypadx+53, kKeypady+5);
196 	singleKey(25, kKeypadx+9,  kKeypady+23);
197 	singleKey(26, kKeypadx+31, kKeypady+23);
198 	singleKey(27, kKeypadx+53, kKeypady+23);
199 	singleKey(28, kKeypadx+9,  kKeypady+41);
200 	singleKey(29, kKeypadx+31, kKeypady+41);
201 	singleKey(30, kKeypadx+53, kKeypady+41);
202 	singleKey(31, kKeypadx+9,  kKeypady+59);
203 	singleKey(32, kKeypadx+31, kKeypady+59);
204 	if (_lightCount) {
205 		--_lightCount;
206 		uint8 frameIndex;
207 		uint16 y;
208 		if (_vars._lockStatus) {
209 			frameIndex = 36;
210 			y = kKeypady-1+63;
211 		} else {
212 			frameIndex = 41;
213 			y = kKeypady+4+63;
214 		}
215 		if ((_lightCount >= 60) && (_lightCount < 100))
216 			--frameIndex;
217 		showFrame(_keypadGraphics, kKeypadx+60, y, frameIndex, 0);
218 	}
219 }
220 
singleKey(uint8 key,uint16 x,uint16 y)221 void DreamWebEngine::singleKey(uint8 key, uint16 x, uint16 y) {
222 	if (key == _graphicPress) {
223 		key += 11;
224 		if (_pressCount < 8)
225 			key -= 11;
226 	}
227 	key -= 20;
228 	showFrame(_keypadGraphics, x, y, key, 0);
229 }
230 
dumpKeypad()231 void DreamWebEngine::dumpKeypad() {
232 	multiDump(kKeypadx - 3, kKeypady - 4, 120, 90);
233 }
234 
useMenu()235 void DreamWebEngine::useMenu() {
236 	getRidOfReels();
237 	loadMenu();
238 	createPanel();
239 	showPanel();
240 	showIcon();
241 	_vars._newObs = 0;
242 	drawFloor();
243 	printSprites();
244 	showFrame(_menuGraphics2, kMenux-48, kMenuy-4, 4, 0);
245 	getUnderMenu();
246 	showFrame(_menuGraphics2, kMenux+54, kMenuy+72, 5, 0);
247 	workToScreenM();
248 	_getBack = 0;
249 	do {
250 		delPointer();
251 		putUnderMenu();
252 		showMenu();
253 		readMouse();
254 		showPointer();
255 		waitForVSync();
256 		dumpPointer();
257 		dumpMenu();
258 		dumpTextLine();
259 		RectWithCallback menuList[] = {
260 			{ kMenux+54,kMenux+68,kMenuy+72,kMenuy+88,&DreamWebEngine::quitKey },
261 			{ 0,320,0,200,&DreamWebEngine::blank },
262 			{ 0xFFFF,0,0,0,0 }
263 		};
264 		checkCoords(menuList);
265 	} while ((_getBack != 1) && !_quitRequested);
266 	_manIsOffScreen = 0;
267 	redrawMainScrn();
268 	_menuGraphics.clear();
269 	_menuGraphics2.clear();
270 	restoreReels();
271 	workToScreenM();
272 }
273 
dumpMenu()274 void DreamWebEngine::dumpMenu() {
275 	multiDump(kMenux, kMenuy, 48, 48);
276 }
277 
getUnderMenu()278 void DreamWebEngine::getUnderMenu() {
279 	multiGet(_underTimedText, kMenux, kMenuy, 48, 48);
280 }
281 
putUnderMenu()282 void DreamWebEngine::putUnderMenu() {
283 	multiPut(_underTimedText, kMenux, kMenuy, 48, 48);
284 }
285 
286 // Note: showoutermenu from the asm version was unused and thus not placed here
287 
showMenu()288 void DreamWebEngine::showMenu() {
289 	++_menuCount;
290 	if (_menuCount == 37*2)
291 		_menuCount = 0;
292 	showFrame(_menuGraphics, kMenux, kMenuy, _menuCount / 2, 0);
293 }
294 
loadMenu()295 void DreamWebEngine::loadMenu() {
296 	loadGraphicsFile(_menuGraphics, "S02"); // sprite name 3
297 	loadGraphicsFile(_menuGraphics2, "G07"); // mon. graphics 2
298 }
299 
viewFolder()300 void DreamWebEngine::viewFolder() {
301 	_manIsOffScreen = 1;
302 	getRidOfAll();
303 	loadFolder();
304 	_folderPage = 0;
305 	showFolder();
306 	workToScreenM();
307 	_getBack = 0;
308 	do {
309 		if (_quitRequested)
310 			break;
311 		delPointer();
312 		readMouse();
313 		showPointer();
314 		waitForVSync();
315 		dumpPointer();
316 		dumpTextLine();
317 		checkFolderCoords();
318 	} while (_getBack == 0);
319 	_manIsOffScreen = 0;
320 	_folderGraphics.clear();
321 	_folderGraphics2.clear();
322 	_folderGraphics3.clear();
323 	_folderCharset.clear();
324 	restoreAll();
325 	redrawMainScrn();
326 	workToScreenM();
327 }
328 
nextFolder()329 void DreamWebEngine::nextFolder() {
330 	if (_folderPage == 12) {
331 		blank();
332 		return;
333 	}
334 	commandOnlyCond(16, 201);
335 	if ((_mouseButton == 1) && (_mouseButton != _oldButton)) {
336 		++_folderPage;
337 		folderHints();
338 		delPointer();
339 		showFolder();
340 		_mouseButton = 0;
341 		checkFolderCoords();
342 		workToScreenM();
343 	}
344 }
345 
folderHints()346 void DreamWebEngine::folderHints() {
347 	if (_folderPage == 5) {
348 		if ((_vars._aideDead != 1) && (getLocation(13) != 1)) {
349 			setLocation(13);
350 			showFolder();
351 			const uint8 *string = getTextInFile1(30);
352 			printDirect(string, 0, 86, 141, true);
353 			workToScreenM();
354 			hangOnP(200);
355 		}
356 	} else if (_folderPage == 9) {
357 		if (getLocation(7) != 1) {
358 			setLocation(7);
359 			showFolder();
360 			const uint8 *string = getTextInFile1(31);
361 			printDirect(string, 0, 86, 141, true);
362 			workToScreenM();
363 			hangOnP(200);
364 		}
365 	}
366 }
367 
lastFolder()368 void DreamWebEngine::lastFolder() {
369 	if (_folderPage == 0) {
370 		blank();
371 		return;
372 	}
373 	commandOnlyCond(17, 202);
374 
375 	if ((_mouseButton == 1) && (_mouseButton != _oldButton)) {
376 		--_folderPage;
377 		delPointer();
378 		showFolder();
379 		_mouseButton = 0;
380 		checkFolderCoords();
381 		workToScreenM();
382 	}
383 }
384 
checkFolderCoords()385 void DreamWebEngine::checkFolderCoords() {
386 	RectWithCallback folderList[] = {
387 		{ 280,320,160,200, &DreamWebEngine::quitKey },
388 		{ 143,300,6,194, &DreamWebEngine::nextFolder },
389 		{ 0,143,6,194, &DreamWebEngine::lastFolder },
390 		{ 0,320,0,200, &DreamWebEngine::blank },
391 		{ 0xFFFF,0,0,0, 0 }
392 	};
393 	checkCoords(folderList);
394 }
395 
loadFolder()396 void DreamWebEngine::loadFolder() {
397 	loadGraphicsFile(_folderGraphics, "G09"); // folder graphics 1
398 	loadGraphicsFile(_folderGraphics2, "G10"); // folder graphics 2
399 	loadGraphicsFile(_folderGraphics3, "G11"); // folder graphics 3
400 	loadGraphicsFile(_folderCharset, "C02"); // character set 3
401 	loadTempText("T50"); // folder text
402 }
403 
showFolder()404 void DreamWebEngine::showFolder() {
405 	_commandType = 255;
406 	if (_folderPage) {
407 		useTempCharset(&_folderCharset);
408 		createPanel2();
409 		showFrame(_folderGraphics, 0, 0, 0, 0);
410 		showFrame(_folderGraphics, 143, 0, 1, 0);
411 		showFrame(_folderGraphics, 0, 92, 2, 0);
412 		showFrame(_folderGraphics, 143, 92, 3, 0);
413 		folderExit();
414 		if (_folderPage != 1)
415 			showLeftPage();
416 		if (_folderPage != 12)
417 			showRightPage();
418 		useCharset1();
419 		underTextLine();
420 	} else {
421 		createPanel2();
422 		showFrame(_folderGraphics3, 143-28, 0, 0, 0);
423 		showFrame(_folderGraphics3, 143-28, 92, 1, 0);
424 		folderExit();
425 		underTextLine();
426 	}
427 }
428 
folderExit()429 void DreamWebEngine::folderExit() {
430 	showFrame(_folderGraphics2, 296, 178, 6, 0);
431 }
432 
showLeftPage()433 void DreamWebEngine::showLeftPage() {
434 	showFrame(_folderGraphics2, 0, 12, 3, 0);
435 	uint16 y = 12+5;
436 	for (uint i = 0; i < 9; ++i) {
437 		showFrame(_folderGraphics2, 0, y, 4, 0);
438 		y += 16;
439 	}
440 	showFrame(_folderGraphics2, 0, y, 5, 0);
441 	_lineSpacing = 8;
442 	_charShift = 91;
443 
444 	if (getLanguage() == Common::RU_RUS)
445 		_charShift = 182;
446 
447 	uint8 pageIndex = _folderPage - 2;
448 	const uint8 *string = getTextInFile1(pageIndex * 2);
449 	y = 48;
450 	for (uint i = 0; i < 2; ++i) {
451 		uint8 lastChar;
452 		do {
453 			lastChar = printDirect(&string, 2, &y, 140, false, true);
454 			y += _lineSpacing;
455 		} while (lastChar != '\0');
456 	}
457 	_charShift = 0;
458 	_lineSpacing = 10;
459 	uint8 *bufferToSwap = workspace() + (48*kScreenwidth)+2;
460 	for (uint i = 0; i < 120; ++i) {
461 		for (uint j = 0; j < 65; ++j) {
462 			SWAP(bufferToSwap[j], bufferToSwap[130 - j]);
463 		}
464 		bufferToSwap += kScreenwidth;
465 	}
466 }
467 
showRightPage()468 void DreamWebEngine::showRightPage() {
469 	showFrame(_folderGraphics2, 143, 12, 0, 0);
470 	uint16 y = 12+37;
471 	for (uint i = 0; i < 7; ++i) {
472 		showFrame(_folderGraphics2, 143, y, 1, 0);
473 		y += 16;
474 	}
475 
476 	showFrame(_folderGraphics2, 143, y, 2, 0);
477 	_lineSpacing = 8;
478 	uint8 pageIndex = _folderPage - 1;
479 	const uint8 *string = getTextInFile1(pageIndex * 2);
480 	y = 48;
481 	for (uint i = 0; i < 2; ++i) {
482 		uint8 lastChar;
483 		do {
484 			lastChar = printDirect(&string, 152, &y, 140, false, true);
485 			y += _lineSpacing;
486 		} while (lastChar != '\0');
487 	}
488 	_lineSpacing = 10;
489 }
490 
enterSymbol()491 void DreamWebEngine::enterSymbol() {
492 	_manIsOffScreen = 1;
493 	getRidOfReels();
494 	loadGraphicsFile(_symbolGraphics, "G12"); // symbol graphics
495 	_symbolTopX = 24;
496 	_symbolTopDir = 0;
497 	_symbolBotX = 24;
498 	_symbolBotDir = 0;
499 	redrawMainScrn();
500 	showSymbol();
501 	underTextLine();
502 	workToScreenM();
503 	_getBack = 0;
504 	do {
505 		delPointer();
506 		updateSymbolTop();
507 		updateSymbolBot();
508 		showSymbol();
509 		readMouse();
510 		showPointer();
511 		waitForVSync();
512 		dumpPointer();
513 		dumpTextLine();
514 		dumpSymbol();
515 		RectWithCallback symbolList[] = {
516 			{ kSymbolx+40,kSymbolx+64,kSymboly+2,kSymboly+16,&DreamWebEngine::quitSymbol },
517 			{ kSymbolx,kSymbolx+52,kSymboly+20,kSymboly+50,&DreamWebEngine::setTopLeft },
518 			{ kSymbolx+52,kSymbolx+104,kSymboly+20,kSymboly+50,&DreamWebEngine::setTopRight },
519 			{ kSymbolx,kSymbolx+52,kSymboly+50,kSymboly+80,&DreamWebEngine::setBotLeft },
520 			{ kSymbolx+52,kSymbolx+104,kSymboly+50,kSymboly+80,&DreamWebEngine::setBotRight },
521 			{ 0,320,0,200,&DreamWebEngine::blank },
522 			{ 0xFFFF,0,0,0,0 }
523 		};
524 		checkCoords(symbolList);
525 	} while ((_getBack == 0) && !_quitRequested);
526 	if ((_symbolBotNum == 3) && (_symbolTopNum == 5)) {
527 		removeSetObject(43);
528 		placeSetObject(46);
529 		turnAnyPathOn(0, _roomNum + 12);
530 		_manIsOffScreen = 0;
531 		redrawMainScrn();
532 		_symbolGraphics.clear();
533 		restoreReels();
534 		workToScreenM();
535 		_sound->playChannel1(13);
536 	} else {
537 		removeSetObject(46);
538 		placeSetObject(43);
539 		turnAnyPathOff(0, _roomNum + 12);
540 		_manIsOffScreen = 0;
541 		redrawMainScrn();
542 		_symbolGraphics.clear();
543 		restoreReels();
544 		workToScreenM();
545 	}
546 }
547 
quitSymbol()548 void DreamWebEngine::quitSymbol() {
549 	if (_symbolTopX != 24 || _symbolBotX != 24) {
550 		blank();
551 		return;
552 	};
553 
554 	commandOnlyCond(18, 222);
555 
556 	if (_mouseButton == _oldButton)
557 		return;	// notqs
558 
559 	if (!(_mouseButton & 1))
560 		return;
561 
562 	_getBack = 1;
563 }
564 
setTopLeft()565 void DreamWebEngine::setTopLeft() {
566 	if (_symbolTopDir != 0) {
567 		blank();
568 		return;
569 	}
570 
571 	commandOnlyCond(19, 210);
572 
573 	if (_mouseButton != 0)
574 		_symbolTopDir = -1;
575 }
576 
setTopRight()577 void DreamWebEngine::setTopRight() {
578 	if (_symbolTopDir != 0) {
579 		blank();
580 		return;
581 	}
582 
583 	commandOnlyCond(20, 211);
584 
585 	if (_mouseButton != 0)
586 		_symbolTopDir = +1;
587 }
588 
setBotLeft()589 void DreamWebEngine::setBotLeft() {
590 	if (_symbolBotDir != 0) {
591 		blank();
592 		return;
593 	}
594 
595 	commandOnlyCond(21, 212);
596 
597 	if (_mouseButton != 0)
598 		_symbolBotDir = -1;
599 }
600 
setBotRight()601 void DreamWebEngine::setBotRight() {
602 	if (_symbolBotDir != 0) {
603 		blank();
604 		return;
605 	}
606 
607 	commandOnlyCond(22, 213);
608 
609 	if (_mouseButton != 0)
610 		_symbolBotDir = +1;
611 }
612 
dumpSymbol()613 void DreamWebEngine::dumpSymbol() {
614 	_newTextLine = 0;
615 	multiDump(kSymbolx, kSymboly + 20, 104, 60);
616 }
617 
showSymbol()618 void DreamWebEngine::showSymbol() {
619 	showFrame(_symbolGraphics, kSymbolx, kSymboly, 12, 0);
620 
621 	showFrame(_symbolGraphics, _symbolTopX + kSymbolx-44, kSymboly+20, _symbolTopNum, 32);
622 	uint8 nextTopSymbol = nextSymbol(_symbolTopNum);
623 	showFrame(_symbolGraphics, _symbolTopX + kSymbolx+5, kSymboly+20, nextTopSymbol, 32);
624 	uint8 nextNextTopSymbol = nextSymbol(nextTopSymbol);
625 	showFrame(_symbolGraphics, _symbolTopX + kSymbolx+54, kSymboly+20, nextNextTopSymbol, 32);
626 
627 	showFrame(_symbolGraphics, _symbolBotX + kSymbolx-44, kSymboly+49, 6 + _symbolBotNum, 32);
628 	uint8 nextBotSymbol = nextSymbol(_symbolBotNum);
629 	showFrame(_symbolGraphics, _symbolBotX + kSymbolx+5, kSymboly+49, 6 + nextBotSymbol, 32);
630 	uint8 nextNextBotSymbol = nextSymbol(nextBotSymbol);
631 	showFrame(_symbolGraphics, _symbolBotX + kSymbolx+54, kSymboly+49, 6 + nextNextBotSymbol, 32);
632 }
633 
nextSymbol(uint8 symbol)634 uint8 DreamWebEngine::nextSymbol(uint8 symbol) {
635 	uint8 result = symbol + 1;
636 	if (result == 6)
637 		return 0;
638 	if (result == 12)
639 		return 6;
640 	return result;
641 }
642 
updateSymbolTop()643 void DreamWebEngine::updateSymbolTop() {
644 	if (!_symbolTopDir)
645 		return; // topfinished
646 
647 	if (_symbolTopDir == -1) {
648 		// Backward
649 		_symbolTopX--;
650 		if (_symbolTopX != (byte)-1) {
651 			// Not wrapping
652 			if (_symbolTopX != 24)
653 				return; // topfinished
654 			_symbolTopDir = 0;
655 		} else {
656 			_symbolTopX = 48;
657 			_symbolTopNum++;
658 			if (_symbolTopNum != 6)
659 				return; // topfinished
660 			_symbolTopNum = 0;
661 		}
662 	} else {
663 		// Forward
664 		_symbolTopX++;
665 		if (_symbolTopX != 49) {
666 			// Not wrapping
667 			if (_symbolTopX != 24)
668 				return; // topfinished
669 			_symbolTopDir = 0;
670 		} else {
671 			_symbolTopX = 0;
672 			_symbolTopNum--;
673 			if (_symbolTopNum != (byte)-1)
674 				return; // topfinished
675 			_symbolTopNum = 5;
676 		}
677 	}
678 }
679 
updateSymbolBot()680 void DreamWebEngine::updateSymbolBot() {
681 	if (!_symbolBotDir)
682 		return; // botfinished
683 
684 	if (_symbolBotDir == -1) {
685 		// Backward
686 		_symbolBotX--;
687 		if (_symbolBotX != (byte)-1) {
688 			// Not wrapping
689 			if (_symbolBotX != 24)
690 				return; // botfinished
691 			_symbolBotDir = 0;
692 		} else {
693 			_symbolBotX = 48;
694 			_symbolBotNum++;
695 			if (_symbolBotNum != 6)
696 				return; // botfinished
697 			_symbolBotNum = 0;
698 		}
699 	} else {
700 		// Forward
701 		_symbolBotX++;
702 		if (_symbolBotX != 49) {
703 			// Not wrapping
704 			if (_symbolBotX != 24)
705 				return; // botfinished
706 			_symbolBotDir = 0;
707 		} else {
708 			_symbolBotX = 0;
709 			_symbolBotNum--;
710 			if (_symbolBotNum != (byte)-1)
711 				return; // botfinished
712 			_symbolBotNum = 5;
713 		}
714 	}
715 }
716 
useDiary()717 void DreamWebEngine::useDiary() {
718 	getRidOfReels();
719 	loadGraphicsFile(_diaryGraphics, "G14");
720 	loadTempText("T51");
721 	loadGraphicsFile(_diaryCharset, "C02");
722 	createPanel();
723 	showIcon();
724 	showDiary();
725 	underTextLine();
726 	showDiaryPage();
727 	readMouse();
728 	showPointer();
729 	workToScreen();
730 	delPointer();
731 	_getBack = 0;
732 
733 	RectWithCallback diaryList[] = {
734 		{ kDiaryx+94,kDiaryx+110,kDiaryy+97,kDiaryy+113,&DreamWebEngine::diaryKeyN },
735 		{ kDiaryx+151,kDiaryx+167,kDiaryy+71,kDiaryy+87,&DreamWebEngine::diaryKeyP },
736 		{ kDiaryx+176,kDiaryx+192,kDiaryy+108,kDiaryy+124,&DreamWebEngine::quitKey },
737 		{ 0,320,0,200,&DreamWebEngine::blank },
738 		{ 0xFFFF,0,0,0,0 }
739 	};
740 
741 	do {
742 		delPointer();
743 		readMouse();
744 		showDiaryKeys();
745 		showPointer();
746 		waitForVSync();
747 		dumpPointer();
748 		dumpDiaryKeys();
749 		dumpTextLine();
750 		checkCoords(diaryList);
751 	} while (!_getBack && !_quitRequested);
752 
753 
754 	_diaryGraphics.clear();
755 	getRidOfTempText();
756 	_diaryCharset.clear();
757 	restoreReels();
758 	_manIsOffScreen = 0;
759 	redrawMainScrn();
760 	workToScreenM();
761 }
762 
showDiary()763 void DreamWebEngine::showDiary() {
764 	showFrame(_diaryGraphics, kDiaryx, kDiaryy + 37, 1, 0);
765 	showFrame(_diaryGraphics, kDiaryx + 176, kDiaryy + 108, 2, 0);
766 }
767 
showDiaryKeys()768 void DreamWebEngine::showDiaryKeys() {
769 	if (!_pressCount)
770 		return; // nokeyatall
771 
772 	_pressCount--;
773 
774 	if (!_pressCount)
775 		return; // nokeyatall
776 
777 	if (_pressed == 'N') {
778 		byte frame = (_pressCount == 1) ? 3 : 4;
779 		showFrame(_diaryGraphics, kDiaryx + 94, kDiaryy + 97, frame, 0);
780 	} else {
781 		byte frame = (_pressCount == 1) ? 5 : 6;
782 		showFrame(_diaryGraphics, kDiaryx + 151, kDiaryy + 71, frame, 0);
783 	}
784 
785 	if (_pressCount == 1)
786 		showDiaryPage();
787 }
788 
dumpDiaryKeys()789 void DreamWebEngine::dumpDiaryKeys() {
790 	if (_pressCount == 1) {
791 		if (_vars._sartainDead != 1 && _diaryPage == 5 && getLocation(6) != 1) {
792 			// Add Sartain Industries note
793 			setLocation(6);
794 			delPointer();
795 			const uint8 *string = getTextInFile1(12);
796 			printDirect(string, 70, 106, 241, 241 & 1);
797 			workToScreenM();
798 			hangOnP(200);
799 			createPanel();
800 			showIcon();
801 			showDiary();
802 			showDiaryPage();
803 			workToScreenM();
804 			showPointer();
805 			return;
806 		} else {
807 			multiDump(kDiaryx + 48, kDiaryy + 15, 200, 16);
808 		}
809 	}
810 
811 	multiDump(kDiaryx + 94, kDiaryy + 97, 16, 16);
812 	multiDump(kDiaryx + 151, kDiaryy + 71, 16, 16);
813 }
814 
diaryKeyP()815 void DreamWebEngine::diaryKeyP() {
816 	commandOnlyCond(23, 214);
817 
818 	if (!_mouseButton ||
819 		_oldButton == _mouseButton ||
820 		_pressCount)
821 		return; // notkeyp
822 
823 	_sound->playChannel1(16);
824 	_pressCount = 12;
825 	_pressed = 'P';
826 	_diaryPage--;
827 
828 	if (_diaryPage == 0xFF)
829 		_diaryPage = 11;
830 }
831 
diaryKeyN()832 void DreamWebEngine::diaryKeyN() {
833 	commandOnlyCond(23, 213);
834 
835 	if (!_mouseButton ||
836 		_oldButton == _mouseButton ||
837 		_pressCount)
838 		return; // notkeyn
839 
840 	_sound->playChannel1(16);
841 	_pressCount = 12;
842 	_pressed = 'N';
843 	_diaryPage++;
844 
845 	if (_diaryPage == 12)
846 		_diaryPage = 0;
847 }
848 
showDiaryPage()849 void DreamWebEngine::showDiaryPage() {
850 	showFrame(_diaryGraphics, kDiaryx, kDiaryy, 0, 0);
851 	useTempCharset(&_diaryCharset);
852 
853 	if (getLanguage() == Common::RU_RUS)
854 		useCharsetTempgraphics();
855 
856 	_charShift = 91+91;
857 	const uint8 *string = getTextInFile1(_diaryPage);
858 	uint16 y = kDiaryy + 16;
859 	printDirect(&string, kDiaryx + 48, &y, 240, 240 & 1, true);
860 	y = kDiaryy + 16;
861 	printDirect(&string, kDiaryx + 129, &y, 240, 240 & 1, true);
862 	y = kDiaryy + 23;
863 	printDirect(&string, kDiaryx + 48, &y, 240, 240 & 1, true);
864 	_charShift = 0;
865 	useCharset1();
866 }
867 
868 } // End of namespace DreamWeb
869