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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
/* 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/file.h"
#include "graphics/dither.h"
#include "gob/gob.h"
#include "gob/inter.h"
#include "gob/helper.h"
#include "gob/global.h"
#include "gob/dataio.h"
#include "gob/game.h"
#include "gob/expression.h"
#include "gob/script.h"
#include "gob/resources.h"
#include "gob/hotspots.h"
#include "gob/draw.h"
#include "gob/sound/sound.h"
#include "gob/videoplayer.h"
namespace Gob {
#define OPCODEVER Inter_v6
#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_v6::Inter_v6(GobEngine *vm) : Inter_v5(vm) {
_gotFirstPalette = false;
}
void Inter_v6::setupOpcodesDraw() {
Inter_v5::setupOpcodesDraw();
OPCODEDRAW(0x40, o6_totSub);
OPCODEDRAW(0x83, o6_playVmdOrMusic);
OPCODEDRAW(0x85, o6_openItk);
}
void Inter_v6::setupOpcodesFunc() {
Inter_v5::setupOpcodesFunc();
OPCODEFUNC(0x03, o6_loadCursor);
OPCODEFUNC(0x09, o6_assign);
OPCODEFUNC(0x13, o6_palLoad);
OPCODEFUNC(0x19, o6_removeHotspot);
OPCODEFUNC(0x33, o6_fillRect);
}
void Inter_v6::setupOpcodesGob() {
}
void Inter_v6::o6_totSub() {
char totFile[14];
byte length;
int flags;
int i;
length = _vm->_game->_script->readByte();
if ((length & 0x7F) > 13)
error("Length in o2_totSub is greater than 13 (%d)", length);
if (length & 0x80) {
_vm->_game->_script->evalExpr(0);
strcpy(totFile, _vm->_game->_script->getResultStr());
} else {
for (i = 0; i < length; i++)
totFile[i] = _vm->_game->_script->readChar();
totFile[i] = 0;
}
flags = _vm->_game->_script->readByte();
if (flags & 0x40)
warning("Urban Stub: o6_totSub(), flags & 0x40");
_vm->_game->totSub(flags, totFile);
}
void Inter_v6::o6_playVmdOrMusic() {
char fileName[128];
bool close;
_vm->_game->_script->evalExpr(0);
strncpy0(fileName, _vm->_game->_script->getResultStr(), 127);
VideoPlayer::Properties props;
props.x = _vm->_game->_script->readValExpr();
props.y = _vm->_game->_script->readValExpr();
props.startFrame = _vm->_game->_script->readValExpr();
props.lastFrame = _vm->_game->_script->readValExpr();
props.breakKey = _vm->_game->_script->readValExpr();
props.flags = _vm->_game->_script->readValExpr();
props.palStart = _vm->_game->_script->readValExpr();
props.palEnd = _vm->_game->_script->readValExpr();
props.palCmd = 1 << (props.flags & 0x3F);
props.forceSeek = true;
debugC(1, kDebugVideo, "Playing video \"%s\" @ %d+%d, frames %d - %d, "
"paletteCmd %d (%d - %d), flags %X", fileName,
props.x, props.y, props.startFrame, props.lastFrame,
props.palCmd, props.palStart, props.palEnd, props.flags);
close = false;
if (props.lastFrame == -1) {
close = true;
} else if (props.lastFrame == -5) {
// warning("Urban/Playtoons Stub: Stop without delay");
_vm->_sound->bgStop();
return;
} else if (props.lastFrame == -6) {
// warning("Urban/Playtoons Stub: Video/Music command -6 (cache video)");
return;
} else if (props.lastFrame == -7) {
// warning("Urban/Playtoons Stub: Video/Music command -6 (flush cache)");
return;
} else if ((props.lastFrame == -8) || (props.lastFrame == -9)) {
if (!strchr(fileName, '.'))
strcat(fileName, ".WA8");
probe16bitMusic(fileName);
if (props.lastFrame == -9) {
warning("Urban/Playtoons Stub: delayed stop not implemented");
}
_vm->_sound->bgStop();
_vm->_sound->bgPlay(fileName, SOUND_WAV);
return;
} else if (props.lastFrame <= -10) {
_vm->_vidPlayer->closeVideo();
warning("Urban/Playtoons Stub: Video/Music command %d (close video?), %s", props.lastFrame, fileName);
if (props.lastFrame <= -100)
props.lastFrame += 100;
if (((-props.lastFrame) % 10 == 3) && (props.lastFrame <= -20))
_vm->_sound->bgPlay(fileName, SOUND_WAV);
} else if (props.lastFrame < 0) {
warning("Urban/Playtoons Stub: Unknown Video/Music command: %d, %s", props.lastFrame, fileName);
return;
}
if (props.startFrame == -2) {
props.startFrame = 0;
props.lastFrame = -1;
close = false;
}
_vm->_vidPlayer->evaluateFlags(props);
int slot;
if ((fileName[0] != 0) && ((slot = _vm->_vidPlayer->openVideo(true, fileName, props)) < 0)) {
WRITE_VAR(11, (uint32) -1);
return;
}
if (props.startFrame >= 0)
_vm->_vidPlayer->play(slot, props);
if (close)
_vm->_vidPlayer->closeVideo(slot);
}
void Inter_v6::o6_openItk() {
char fileName[32];
_vm->_game->_script->evalExpr(0);
strncpy0(fileName, _vm->_game->_script->getResultStr(), 27);
if (!strchr(fileName, '.'))
strcat(fileName, ".ITK");
_vm->_dataIO->openDataFile(fileName, true);
// WORKAROUND: The CD number detection in Urban Runner is quite daft
// (it checks CD1.ITK - CD4.ITK and the first that's found determines
// the CD number), while its NO_CD modus wants everything in CD1.ITK.
// So we just open the other ITKs, too.
if (_vm->_global->_noCd && !scumm_stricmp(fileName, "CD1.ITK")) {
_vm->_dataIO->openDataFile("CD2.ITK", true);
_vm->_dataIO->openDataFile("CD3.ITK", true);
_vm->_dataIO->openDataFile("CD4.ITK", true);
}
}
bool Inter_v6::o6_loadCursor(OpFuncParams ¶ms) {
int16 id = _vm->_game->_script->readInt16();
if ((id == -1) || (id == -2)) {
char file[10];
if (id == -1) {
for (int i = 0; i < 9; i++)
file[i] = _vm->_game->_script->readChar();
} else
strncpy(file, GET_VAR_STR(_vm->_game->_script->readInt16()), 10);
file[9] = '\0';
uint16 start = _vm->_game->_script->readUint16();
int8 index = _vm->_game->_script->readInt8();
VideoPlayer::Properties props;
props.sprite = -1;
int vmdSlot = _vm->_vidPlayer->openVideo(false, file, props);
if (vmdSlot == -1) {
warning("Can't open video \"%s\" as cursor", file);
return false;
}
int16 framesCount = _vm->_vidPlayer->getFrameCount(vmdSlot);
for (int i = 0; i < framesCount; i++) {
props.startFrame = i;
props.lastFrame = i;
_vm->_vidPlayer->play(vmdSlot, props);
_vm->_vidPlayer->copyFrame(vmdSlot, _vm->_draw->_cursorSprites->getVidMem(),
0, 0, _vm->_draw->_cursorWidth, _vm->_draw->_cursorWidth,
(start + i) * _vm->_draw->_cursorWidth, 0,
_vm->_draw->_cursorSprites->getWidth());
}
_vm->_vidPlayer->closeVideo(vmdSlot);
_vm->_draw->_cursorAnimLow[index] = start;
_vm->_draw->_cursorAnimHigh[index] = framesCount + start - 1;
_vm->_draw->_cursorAnimDelays[index] = 10;
return false;
}
int8 index = _vm->_game->_script->readInt8();
if ((index * _vm->_draw->_cursorWidth) >= _vm->_draw->_cursorSprites->getWidth())
return false;
Resource *resource = _vm->_game->_resources->getResource((uint16) id);
if (!resource)
return false;
_vm->_video->fillRect(*_vm->_draw->_cursorSprites,
index * _vm->_draw->_cursorWidth, 0,
index * _vm->_draw->_cursorWidth + _vm->_draw->_cursorWidth - 1,
_vm->_draw->_cursorHeight - 1, 0);
_vm->_video->drawPackedSprite(resource->getData(),
resource->getWidth(), resource->getHeight(),
index * _vm->_draw->_cursorWidth, 0, 0, *_vm->_draw->_cursorSprites);
_vm->_draw->_cursorAnimLow[index] = 0;
delete resource;
return false;
}
bool Inter_v6::o6_assign(OpFuncParams ¶ms) {
uint16 size, destType;
uint16 dest = _vm->_game->_script->readVarIndex(&size, &destType);
if (size != 0) {
int16 src;
_vm->_game->_script->push();
src = _vm->_game->_script->readVarIndex(&size, 0);
memcpy(_vm->_inter->_variables->getAddressOff8(dest),
_vm->_inter->_variables->getAddressOff8((uint16) src), size * 4);
_vm->_game->_script->pop();
_vm->_game->_script->evalExpr(&src);
return false;
}
byte loopCount;
if (_vm->_game->_script->peekByte() == 98) {
_vm->_game->_script->skip(1);
loopCount = _vm->_game->_script->readByte();
for (int i = 0; i < loopCount; i++) {
uint8 c = _vm->_game->_script->readByte();
uint16 n = _vm->_game->_script->readUint16();
memset(_vm->_inter->_variables->getAddressOff8(dest), c, n);
dest += n;
}
return false;
} else if (_vm->_game->_script->peekByte() == 99) {
_vm->_game->_script->skip(1);
loopCount = _vm->_game->_script->readByte();
} else
loopCount = 1;
for (int i = 0; i < loopCount; i++) {
int16 result;
int16 srcType = _vm->_game->_script->evalExpr(&result);
switch (destType) {
case TYPE_VAR_INT8:
case TYPE_ARRAY_INT8:
WRITE_VARO_UINT8(dest + i, _vm->_game->_script->getResultInt());
break;
case TYPE_VAR_INT16:
case TYPE_ARRAY_INT16:
WRITE_VARO_UINT16(dest + i * 2, _vm->_game->_script->getResultInt());
break;
case TYPE_VAR_INT32:
case TYPE_ARRAY_INT32:
WRITE_VAR_OFFSET(dest + i * 4, _vm->_game->_script->getResultInt());
break;
case TYPE_VAR_INT32_AS_INT16:
WRITE_VARO_UINT16(dest + i * 4, _vm->_game->_script->getResultInt());
break;
case TYPE_VAR_STR:
case TYPE_ARRAY_STR:
if (srcType == TYPE_IMM_INT16)
WRITE_VARO_UINT8(dest, result);
else
WRITE_VARO_STR(dest, _vm->_game->_script->getResultStr());
break;
}
}
return false;
}
bool Inter_v6::o6_palLoad(OpFuncParams ¶ms) {
o1_palLoad(params);
if (_gotFirstPalette)
_vm->_video->_palLUT->setPalette((const byte *)_vm->_global->_pPaletteDesc->vgaPal,
Graphics::PaletteLUT::kPaletteRGB, 6, 0);
_gotFirstPalette = true;
return false;
}
bool Inter_v6::o6_removeHotspot(OpFuncParams ¶ms) {
int16 id;
uint8 stateType1 = Hotspots::kStateFilledDisabled | Hotspots::kStateType1;
uint8 stateType2 = Hotspots::kStateFilledDisabled | Hotspots::kStateType2;
uint8 stateDisabled = Hotspots::kStateDisabled;
id = _vm->_game->_script->readValExpr();
switch (id + 5) {
case 0:
_vm->_game->_hotspots->push(1);
break;
case 1:
_vm->_game->_hotspots->pop();
break;
case 2:
_vm->_game->_hotspots->push(2);
break;
case 3:
_vm->_game->_hotspots->removeState(stateType1);
_vm->_game->_hotspots->removeState(stateDisabled);
break;
case 4:
_vm->_game->_hotspots->removeState(stateType2);
break;
default:
_vm->_game->_hotspots->remove((stateType2 << 12) + id);
break;
}
return false;
}
bool Inter_v6::o6_fillRect(OpFuncParams ¶ms) {
int16 destSurf;
_vm->_draw->_destSurface = destSurf = _vm->_game->_script->readInt16();
_vm->_draw->_destSpriteX = _vm->_game->_script->readValExpr();
_vm->_draw->_destSpriteY = _vm->_game->_script->readValExpr();
_vm->_draw->_spriteRight = _vm->_game->_script->readValExpr();
_vm->_draw->_spriteBottom = _vm->_game->_script->readValExpr();
_vm->_game->_script->evalExpr(0);
_vm->_draw->_backColor = _vm->_game->_script->getResultInt() & 0xFFFF;
_vm->_draw->_pattern = _vm->_game->_script->getResultInt() >> 16;
if (_vm->_draw->_pattern != 0)
warning("Urban Stub: o6_fillRect(), _pattern = %d", _vm->_draw->_pattern);
if (_vm->_draw->_spriteRight < 0) {
_vm->_draw->_destSpriteX += _vm->_draw->_spriteRight - 1;
_vm->_draw->_spriteRight = -_vm->_draw->_spriteRight + 2;
}
if (_vm->_draw->_spriteBottom < 0) {
_vm->_draw->_destSpriteY += _vm->_draw->_spriteBottom - 1;
_vm->_draw->_spriteBottom = -_vm->_draw->_spriteBottom + 2;
}
if (destSurf & 0x80) {
warning("Urban Stub: o6_fillRect(), destSurf & 0x80");
return false;
}
if (!_vm->_draw->_spritesArray[(destSurf > 100) ? (destSurf - 80) : destSurf])
return false;
_vm->_draw->spriteOperation(DRAW_FILLRECT);
return false;
}
void Inter_v6::probe16bitMusic(char *fileName) {
int len = strlen(fileName);
if (len < 4)
return;
if (scumm_stricmp(fileName + len - 4, ".WA8"))
return;
fileName[len - 1] = 'V';
if (_vm->_dataIO->existData(fileName))
return;
fileName[len - 1] = '8';
}
} // End of namespace Gob
|