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/config-manager.h"
24 
25 #include "agos/intern.h"
26 #include "agos/agos.h"
27 
28 namespace AGOS {
29 
AGOSEngine_PN(OSystem * system,const AGOSGameDescription * gd)30 AGOSEngine_PN::AGOSEngine_PN(OSystem *system, const AGOSGameDescription *gd)
31 	: AGOSEngine(system, gd) {
32 
33 	_stackbase = 0;
34 	_tagOfActiveDoline = 0;
35 	_dolineReturnVal = 0;
36 
37 	_dataBase = 0;
38 	_dataBaseSize = 0;
39 	_textBase = 0;
40 	_textBaseSize = 0;
41 
42 	memset(_buffer, 0, sizeof(_buffer));
43 	memset(_inputline, 0, sizeof(_inputline));
44 	memset(_saveFile, 0, sizeof(_saveFile));
45 	memset(_sb, 0, sizeof(_sb));
46 	memset(_wordcp, 0, sizeof(_wordcp));
47 
48 	memset(_objectName1, 0, sizeof(_objectName1));
49 	memset(_objectName2, 0, sizeof(_objectName2));
50 
51 	_dragStore = 0;
52 	_hitCalled = 0;
53 	_inputReady = false;
54 	_inputting = false;
55 	_intputCounter = 0;
56 	_inputMax = 0;
57 	_mousePrintFG = 0;
58 	_mouseString = 0;
59 	_mouseString1 = 0;
60 	memset(_inMessage, 0, sizeof(_inMessage));
61 	memset(_placeMessage, 0, sizeof(_placeMessage));
62 
63 	memset(_quickptr, 0, sizeof(_quickptr));
64 	memset(_quickshort, 0, sizeof(_quickshort));
65 
66 	_noScanFlag = false;
67 	memset(_keyboardBuffer, 0, sizeof(_keyboardBuffer));
68 
69 	_objects = 0;
70 	_objectCountS = 0;
71 
72 	_bp = 0;
73 	_xofs = 0;
74 	_havinit = 0;
75 	_seed = 0;
76 
77 	_curwrdptr = 0;
78 	_inpp = 0;
79 	_fnst = 0;
80 	_linembr = 0;
81 	_linct = 0;
82 	_procnum = 0;
83 
84 	_linebase = 0;
85 	_workptr = 0;
86 }
87 
~AGOSEngine_PN()88 AGOSEngine_PN::~AGOSEngine_PN() {
89 	free(_dataBase);
90 	free(_textBase);
91 
92 }
93 
94 const byte egaPalette[48] = {
95 	  0,   0,   0,
96 	  0,   0, 170,
97 	  0, 170,   0,
98 	  0, 170, 170,
99 	170,   0,   0,
100 	170,   0, 170,
101 	170,  85,   0,
102 	170, 170, 170,
103 	 85,  85,  85,
104 	 85,  85, 255,
105 	 85, 255,  85,
106 	 85, 255, 255,
107 	255,  85,  85,
108 	255,  85, 255,
109 	255, 255,  85,
110 	255, 255, 255
111 };
112 
go()113 Common::Error AGOSEngine_PN::go() {
114 	loadGamePcFile();
115 
116 	if (getFileName(GAME_ICONFILE) != NULL) {
117 		loadIconFile();
118 	}
119 
120 	setupBoxes();
121 
122 	vc34_setMouseOff();
123 
124 	addVgaEvent(_frameCount, ANIMATE_INT, NULL, 0, 0);
125 
126 	if (getFeatures() & GF_EGA) {
127 		// Set EGA Palette
128 		memcpy(_displayPalette, egaPalette, sizeof(egaPalette));
129 		_paletteFlag = 1;
130 	}
131 
132 	_inputWindow = _windowArray[2] = openWindow(0, 192, 40, 1, 1, 0, 15);
133 	_textWindow = _windowArray[0] = openWindow(1, 136, 38, 6, 1, 0, 15);
134 
135 	if (getFeatures() & GF_DEMO) {
136 		demoSeq();
137 	} else {
138 		introSeq();
139 		processor();
140 	}
141 
142 	return Common::kNoError;
143 }
144 
demoSeq()145 void AGOSEngine_PN::demoSeq() {
146 	while (!shouldQuit()) {
147 		loadZone(0);
148 		setWindowImage(3, 0);
149 		while (!shouldQuit() && _variableArray[228] != 1)
150 			delay(1);
151 
152 		loadZone(1);
153 		setWindowImage(0, 0);
154 		while (!shouldQuit() && _variableArray[228] != 2)
155 			delay(1);
156 
157 		loadZone(2);
158 		setWindowImage(0, 0);
159 		while (!shouldQuit() && _variableArray[228] != 3)
160 			delay(1);
161 	}
162 }
163 
introSeq()164 void AGOSEngine_PN::introSeq() {
165 	loadZone(25); // Zone 'I'
166 	setWindowImage(3, 0);
167 
168 	_exitCutscene = false;
169 	while (!shouldQuit() && !_exitCutscene && _variableArray[228] != 1) {
170 		processSpecialKeys();
171 		delay(1);
172 	}
173 
174 	setWindowImage(3, 3);
175 	delay(100);
176 
177 	loadZone(27); // Zone 'K'
178 	setWindowImage(3, 0);
179 
180 	_exitCutscene = false;
181 	while (!shouldQuit() && !_exitCutscene && _variableArray[228] != 2) {
182 		processSpecialKeys();
183 		delay(1);
184 	}
185 }
186 
setupBoxes()187 void AGOSEngine_PN::setupBoxes() {
188 	_hitAreaList = _invHitAreas;
189 	// Inventory box
190 	defineBox( 0,  11,  68, 16,  26, 25, 0, kOBFDraggable | kOBFUseEmptyLine | kOBFInventoryBox | kOBFNoShowName);
191 	// Room Box
192 	defineBox( 1,  11, 103, 16,  26, 26, 0, kOBFDraggable | kOBFUseEmptyLine | kOBFRoomBox | kOBFNoShowName);
193 	// Exit box
194 	defineBox( 2,  48,   2,  8,  28, 27, 0, kOBFUseEmptyLine | kOBFNoShowName);
195 	// More box
196 	defineBox( 3,  80,   2,  8,  26, 28, 0, kOBFUseEmptyLine | kOBFMoreBox | kOBFNoShowName);
197 	// Close box
198 	defineBox( 4, 110,   2,  8,  28, 29, 0, kOBFUseEmptyLine | kOBFNoShowName);
199 
200 	// Icon boxes
201 	uint8 num = 5;
202 	for (uint8 r = 0; r < 5; r++) {
203 		for (uint8 i = 0; i < 7; i++) {
204 			defineBox(num, 96 + i * 24, 12 + r * 24, 24, 24, 0, 3, kOBFObject | kOBFDraggable);
205 			num++;
206 		}
207 	}
208 
209 	// Mark the end of inventory boxes
210 	HitArea *ha = _hitAreaList + num;
211 	ha->id = 0xFFFF;
212 
213 	_hitAreaList = _hitAreas;
214 	defineBox( 0,  0,    0, 200, 320, 0, 0, kOBFBoxDisabled | kOBFNoShowName);
215 	defineBox( 1, 273,   4,   5,  45, 1, 0, kOBFUseEmptyLine | kOBFNoShowName | kOBFInvertTouch);
216 	defineBox( 2, 273,  12,   5,  45, 2, 0, kOBFUseEmptyLine | kOBFNoShowName | kOBFInvertTouch);
217 	defineBox( 3, 273,  20,   5,  45, 3, 0, kOBFUseEmptyLine | kOBFNoShowName | kOBFInvertTouch);
218 	defineBox( 4, 273,  28,   5,  45, 4, 0, kOBFUseEmptyLine | kOBFNoShowName | kOBFInvertTouch);
219 	defineBox( 5, 273,  36,   5,  45, 5, 0, kOBFUseEmptyLine | kOBFNoShowName | kOBFInvertTouch);
220 	defineBox( 6, 273,  44,   5,  45, 6, 0, kOBFUseEmptyLine | kOBFNoShowName | kOBFInvertTouch);
221 	defineBox( 7, 273,  52,   5,  45, 7, 0, kOBFUseEmptyLine | kOBFNoShowName | kOBFInvertTouch);
222 	defineBox( 8, 273,  60,   5,  45, 8, 0, kOBFUseEmptyLine | kOBFNoShowName | kOBFInvertTouch);
223 	defineBox( 9, 273,  68,   5,  45, 9, 0, kOBFUseEmptyLine | kOBFNoShowName | kOBFInvertTouch);
224 	defineBox(10, 273,  76,   5,  45, 10, 0, kOBFUseEmptyLine | kOBFNoShowName | kOBFInvertTouch);
225 	defineBox(11, 273,  84,   5,  45, 11, 0, kOBFUseEmptyLine | kOBFNoShowName | kOBFInvertTouch);
226 	defineBox(12, 273,  92,   5,  45, 12, 0, kOBFUseEmptyLine | kOBFNoShowName | kOBFInvertTouch);
227 	defineBox(13, 273, 100,   5,  45, 13, 0, kOBFUseEmptyLine | kOBFBoxDisabled | kOBFNoShowName);
228 	defineBox(14, 273, 107,   5,  45, 14, 0, kOBFUseEmptyLine | kOBFNoShowName | kOBFInvertTouch);
229 	defineBox(15, 273, 115,   5,  45, 15, 0, kOBFUseEmptyLine | kOBFNoShowName | kOBFInvertTouch);
230 	defineBox(16, 273, 123,   5,  45, 16, 0, kOBFUseEmptyLine | kOBFBoxDisabled | kOBFNoShowName);
231 	defineBox(17,  20,   5,   7,   7, 17, 0, kOBFUseEmptyLine | kOBFNoShowName);
232 	defineBox(18,  28,  11,   7,  13, 18, 0, kOBFUseEmptyLine | kOBFNoShowName);
233 	defineBox(19,  36,  21,   7,   7, 19, 0, kOBFUseEmptyLine | kOBFNoShowName);
234 	defineBox(20,  27,  31,   7,  13, 20, 0, kOBFUseEmptyLine | kOBFNoShowName);
235 	defineBox(21,  20,  37,   7,   7, 21, 0, kOBFUseEmptyLine | kOBFNoShowName);
236 	defineBox(22,   5,  31,   7,  13, 22, 0, kOBFUseEmptyLine | kOBFNoShowName);
237 	defineBox(23,   4,  21,   7,   7, 23, 0, kOBFUseEmptyLine | kOBFNoShowName);
238 	defineBox(24,   5,  11,   7,  13, 24, 0, kOBFUseEmptyLine | kOBFNoShowName);
239 	defineBox(25,  11,  68,  16,  26, 25, 0, kOBFDraggable | kOBFUseEmptyLine | kOBFInventoryBox | kOBFNoShowName);
240 	defineBox(26,  11, 103,  16,  26, 26, 0, kOBFDraggable | kOBFUseEmptyLine | kOBFRoomBox | kOBFNoShowName);
241 }
242 
processor()243 void AGOSEngine_PN::processor() {
244 	setqptrs();
245 
246 	_tagOfActiveDoline = 0;
247 	int q = 0;
248 	do {
249 		assert(_tagOfActiveDoline == 0);
250 		_dolineReturnVal = 0;
251 
252 		_variableArray[6] = 0;
253 
254 		if (getPlatform() == Common::kPlatformAtariST) {
255 			_variableArray[21] = 2;
256 		} else if (getPlatform() == Common::kPlatformAmiga) {
257 			_variableArray[21] = 0;
258 		} else {
259 			_variableArray[21] = 1;
260 		}
261 
262 		_variableArray[16] = _quickshort[6];
263 		_variableArray[17] = _quickshort[7];
264 		_variableArray[19] = getptr(55L);
265 
266 		// q indicates the process to run and is 0 the first time,
267 		// but 1 later on (i.e., when we are "called" from badload()).
268 		setposition(0, 0);
269 		q = doline(0);
270 	} while (q);
271 }
272 
setqptrs()273 void AGOSEngine_PN::setqptrs() {
274 	for (int i = 0; i < 11; ++i) {
275 		_quickptr[i] = getlong(3 * i);
276 	}
277 	_quickptr[11] = getlong(58L);
278 	_quickptr[12] = getlong(61L);
279 	_quickshort[0] = getptr(35L);
280 	_quickshort[1] = getptr(37L);
281 	_quickshort[2] = getptr(39L);
282 	_quickshort[3] = getptr(41L);
283 	_quickshort[4] = getptr(43L);
284 	_quickshort[5] = getptr(45L);
285 	_quickshort[6] = getptr(51L);
286 	_quickshort[7] = getptr(53L);
287 }
288 
289 } // End of namespace AGOS
290