aboutsummaryrefslogtreecommitdiff
path: root/engines/gob/inter_v7.cpp
blob: 7067969e91d81fd33a1e86d67f50da1c3b4e491f (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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/* 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.
 *
 * $URL$
 * $Id$
 *
 */

#include "common/endian.h"
#include "common/archive.h"

#include "graphics/cursorman.h"

#include "gob/gob.h"
#include "gob/global.h"
#include "gob/inter.h"
#include "gob/game.h"
#include "gob/script.h"
#include "gob/expression.h"

namespace Gob {

#define OPCODEVER Inter_v7
#define OPCODEDRAW(i, x)  _opcodesDraw[i]._OPCODEDRAW(OPCODEVER, x)
#define OPCODEFUNC(i, x)  _opcodesFunc[i]._OPCODEFUNC(OPCODEVER, x)
#define OPCODEGOB(i, x)   _opcodesGob[i]._OPCODEGOB(OPCODEVER, x)

Inter_v7::Inter_v7(GobEngine *vm) : Inter_Playtoons(vm) {
}

void Inter_v7::setupOpcodesDraw() {
	Inter_Playtoons::setupOpcodesDraw();

	OPCODEDRAW(0x0C, o7_draw0x0C);
	OPCODEDRAW(0x0D, o7_loadCursor);
	OPCODEDRAW(0x44, o7_displayWarning);
	OPCODEDRAW(0x45, o7_draw0x45);
	OPCODEDRAW(0x57, o7_intToString);
	OPCODEDRAW(0x59, o7_callGroup);
	OPCODEDRAW(0x5A, o7_loadGroups);
	OPCODEDRAW(0x89, o7_draw0x89);
	OPCODEDRAW(0x8A, o7_findFile);
	OPCODEDRAW(0x8C, o7_getSystemProperty);
	OPCODEDRAW(0x90, o7_loadLBM);
	OPCODEDRAW(0x93, o7_setVolume);
	OPCODEDRAW(0x95, o7_zeroVar);
	OPCODEDRAW(0xA1, o7_getINIValue);
	OPCODEDRAW(0xA2, o7_setINIValue);
	OPCODEDRAW(0xA4, o7_draw0xA4);
	OPCODEDRAW(0xC4, o7_opendBase);
	OPCODEDRAW(0xC5, o7_draw0xC5);
	OPCODEDRAW(0xC6, o7_draw0xC6);
}

void Inter_v7::setupOpcodesFunc() {
	Inter_Playtoons::setupOpcodesFunc();
}

void Inter_v7::setupOpcodesGob() {
	Inter_Playtoons::setupOpcodesGob();

	OPCODEGOB(420, o7_oemToANSI);
}

void Inter_v7::o7_draw0x0C() {
	WRITE_VAR(17, 0);
}

void Inter_v7::o7_loadCursor() {
	int16          cursorIndex = _vm->_game->_script->readValExpr();
	Common::String cursorFile  = _vm->_game->_script->evalString();

	warning("Addy Stub: Load cursor \"%s\" to %d", cursorFile.c_str(), cursorIndex);

	byte cursor[9];
	byte palette[6];

	cursor[0] = 0; cursor[1] = 0; cursor[2] = 0;
	cursor[3] = 0; cursor[4] = 1; cursor[5] = 0;
	cursor[6] = 0; cursor[7] = 0; cursor[8] = 0;

	palette[0] =   0; palette[1] =   0; palette[2] =   0;
	palette[3] = 255; palette[4] = 255; palette[5] = 255;

	CursorMan.pushCursorPalette(palette, 0, 2);
	CursorMan.disableCursorPalette(false);
	CursorMan.replaceCursor(cursor, 3, 3, 1, 1, 255);

	CursorMan.showMouse(true);
}

void Inter_v7::o7_displayWarning() {
	Common::String caption = _vm->_game->_script->evalString();
	Common::String text    = _vm->_game->_script->evalString();
	Common::String source  = _vm->_game->_script->evalString();
	Common::String msg     = _vm->_game->_script->evalString();
	Common::String param   = _vm->_game->_script->evalString();

	warning("%s: %s (%s)", source.c_str(), msg.c_str(), param.c_str());
}

void Inter_v7::o7_draw0x45() {
	Common::String str0 = _vm->_game->_script->evalString();
	Common::String str1 = _vm->_game->_script->evalString();

	warning("Addy Stub Draw 0x45: \"%s\", \"%s\"", str0.c_str(), str1.c_str());
}

void Inter_v7::o7_intToString() {
	uint16 valueIndex = _vm->_game->_script->readVarIndex();
	uint16 destIndex  = _vm->_game->_script->readVarIndex();

	sprintf(GET_VARO_STR(destIndex), "%d", READ_VARO_UINT32(valueIndex));
}

void Inter_v7::o7_callGroup() {
	Common::String str0 = _vm->_game->_script->evalString();
	Common::String str1 = _vm->_game->_script->evalString();

	int16 expr0 = _vm->_game->_script->readValExpr();

	warning("Addy Stub: Call group: \"%s\", \"%s\", %d", str0.c_str(), str1.c_str(), expr0);
}

void Inter_v7::o7_loadGroups() {
	Common::String str0 = _vm->_game->_script->evalString();

	int16 expr0 = _vm->_game->_script->readValExpr();

	warning("Addy Stub: Load groups: \"%s\", %d", str0.c_str(), expr0);
}

void Inter_v7::o7_draw0x89() {
	Common::String str0 = _vm->_game->_script->evalString();
	Common::String str1 = _vm->_game->_script->evalString();

	warning("Addy Stub Draw 0x89: \"%s\", \"%s\"", str0.c_str(), str1.c_str());

	Common::ArchiveMemberList files;

	SearchMan.listMatchingMembers(files, str0);

	if (files.empty()) {
		storeValue(0);
		return;
	}

	storeValue(1);
}

void Inter_v7::o7_findFile() {
	const char *file = _vm->_game->_script->evalString();
	uint16 pathIndex = _vm->_game->_script->readVarIndex();

	if (!strncmp(file, "<ME>", 4))
		file += 4;
	if (!strncmp(file, "<ALLCD>", 7))
		file += 7;

	Common::ArchiveMemberList files;

	SearchMan.listMatchingMembers(files, file);

	if (files.empty()) {
		GET_VARO_STR(pathIndex)[0] = '\0';
		storeValue(0);
		return;
	}

	strcpy(GET_VARO_STR(pathIndex), files.front()->getName().c_str());
	storeValue(1);
}

void Inter_v7::o7_getSystemProperty() {
	const char *property = _vm->_game->_script->evalString();
	if (!scumm_stricmp(property, "TotalPhys")) {
		// HACK
		storeValue(1000000);
		return;
	}

	if (!scumm_stricmp(property, "AvailPhys")) {
		// HACK
		storeValue(1000000);
		return;
	}

	if (!scumm_stricmp(property, "TimeGMT")) {
		renewTimeInVars();
		storeValue(0);
		return;
	}

	warning("Inter_v7::o7_getSystemProperty(): Unknown property \"%s\"", property);
	storeValue(0);
}

void Inter_v7::o7_loadLBM() {
	Common::String file = _vm->_game->_script->evalString();
	if (!file.contains('.'))
		file += ".LBM";

	int16 spriteIndex = _vm->_game->_script->readValExpr();
	int16 left        = _vm->_game->_script->readValExpr();
	int16 top         = _vm->_game->_script->readValExpr();
	int16 width       = _vm->_game->_script->readValExpr();
	int16 height      = _vm->_game->_script->readValExpr();
	int16 x           = _vm->_game->_script->readValExpr();
	int16 y           = _vm->_game->_script->readValExpr();
	int16 transp      = _vm->_game->_script->readValExpr();

	warning("Addy Stub: Load LBM \"%s\", sprite %d, %dx%d+%d+%d @ %d+%d (%d)",
			file.c_str(), spriteIndex, width, height, left, top, x, y, transp);
}

void Inter_v7::o7_setVolume() {
	uint32 volume = _vm->_game->_script->readValExpr();

	warning("Addy Stub: Set volume %d (0 - 100)", volume);
}

void Inter_v7::o7_zeroVar() {
	uint16 index = _vm->_game->_script->readVarIndex();

	WRITE_VARO_UINT32(index, 0);
}

void Inter_v7::o7_getINIValue() {
	const char *file = _vm->_game->_script->evalString();
	if (!strncmp(file, "<ME>", 4))
		file += 4;
	else if (!strncmp(file, "<ALLCD>", 7))
		file += 7;

	Common::String section = _vm->_game->_script->evalString();
	Common::String key     = _vm->_game->_script->evalString();
	Common::String def     = _vm->_game->_script->evalString();

	Common::String value;
	_inis.getValue(value, file, section, key, def);

	storeString(value.c_str());
}

void Inter_v7::o7_setINIValue() {
	const char *file = _vm->_game->_script->evalString();
	if (!strncmp(file, "<ME>", 4))
		file += 4;
	else if (!strncmp(file, "<ALLCD>", 7))
		file += 7;

	Common::String section = _vm->_game->_script->evalString();
	Common::String key     = _vm->_game->_script->evalString();
	Common::String value   = _vm->_game->_script->evalString();

	_inis.setValue(file, section, key, value);
}

void Inter_v7::o7_draw0xA4() {
	Common::String str0 = _vm->_game->_script->evalString();

	int16 expr0 = _vm->_game->_script->readValExpr();
	int16 expr1 = _vm->_game->_script->readValExpr();

	warning("Addy Stub Draw 0xA4: \"%s\", %d, %d", str0.c_str(), expr0, expr1);
}

void Inter_v7::o7_opendBase() {
	Common::String str0 = _vm->_game->_script->evalString();
	Common::String str1 = _vm->_game->_script->evalString();

	warning("Addy Stub: Open dBase file \"%s.dbf\" (%s)", str0.c_str(), str1.c_str());
}

void Inter_v7::o7_draw0xC5() {
	Common::String str0 = _vm->_game->_script->evalString();

	warning("Addy Stub Draw 0xC5: \"%s\"", str0.c_str());
}

void Inter_v7::o7_draw0xC6() {
	Common::String str0 = _vm->_game->_script->evalString();
	Common::String str1 = _vm->_game->_script->evalString();
	Common::String str2 = _vm->_game->_script->evalString();
	Common::String str3 = _vm->_game->_script->evalString();

	int16 index0 = _vm->_game->_script->readVarIndex();

	warning("Addy Stub Draw 0xC6: \"%s\", \"%s\", \"%s\", \"%s\", %d",
			str0.c_str(), str1.c_str(), str2.c_str(), str3.c_str(), index0);
}

void Inter_v7::o7_oemToANSI(OpGobParams &params) {
	_vm->_game->_script->skip(2);
}

void Inter_v7::storeValue(uint16 index, uint16 type, uint32 value) {
	switch (type) {
	case OP_ARRAY_INT8:
	case TYPE_VAR_INT8:
		WRITE_VARO_UINT8(index, value);
		break;

	case TYPE_VAR_INT16:
	case TYPE_VAR_INT32_AS_INT16:
	case TYPE_ARRAY_INT16:
		WRITE_VARO_UINT16(index, value);
		break;

	default:
		WRITE_VARO_UINT32(index, value);
	}
}

void Inter_v7::storeValue(uint32 value) {
	uint16 type;
	uint16 index = _vm->_game->_script->readVarIndex(0, &type);

	storeValue(index, type, value);
}

void Inter_v7::storeString(uint16 index, uint16 type, const char *value) {
	if (type == TYPE_VAR_STR) {
		char *str = GET_VARO_STR(index);

		strncpy(str, value, _vm->_global->_inter_animDataSize);
		str[_vm->_global->_inter_animDataSize - 1] = '\0';

	} else if (type == TYPE_IMM_INT8) {

		strcpy(GET_VARO_STR(index), value);

	} else if (type == TYPE_VAR_INT32) {

		WRITE_VARO_UINT32(index, atoi(value));

	} else if (type == TYPE_VAR_INT16) {

		WRITE_VARO_UINT16(index, atoi(value));
	}
}

void Inter_v7::storeString(const char *value) {
	uint16 type;
	int16 varIndex = _vm->_game->_script->readVarIndex(0, &type);

	storeString(varIndex, type, value);
}

} // End of namespace Gob