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
462
463
464
465
|
/* 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/util.h"
#include "common/events.h"
#include "graphics/cursorman.h"
#include "made/made.h"
#include "made/resource.h"
#include "made/database.h"
#include "made/screen.h"
#include "made/script.h"
#include "made/pmvplayer.h"
#include "made/scriptfuncs.h"
#include "made/music.h"
namespace Made {
/* ScriptFunctionsLgop2 */
typedef Common::Functor2Mem<int16, int16*, int16, ScriptFunctionsLgop2> ExternalFuncLgop2;
#define External(x) \
_externalFuncs.push_back(new ExternalFuncLgop2(this, &ScriptFunctionsLgop2::x)); \
_externalFuncNames.push_back(#x);
void ScriptFunctionsLgop2::setupExternalsTable() {
External(o1_SYSTEM);
External(o1_INITGRAF);
External(o1_RESTOREGRAF);
External(o1_DRAWPIC);
External(o1_CLS);
External(o1_SHOWPAGE);
External(o1_EVENT);
External(o1_EVENTX);
External(o1_EVENTY);
External(o1_EVENTKEY);
External(o1_VISUALFX);
External(o1_PLAYSND);
External(o1_PLAYMUS);
External(o1_STOPMUS);
External(o1_ISMUS);
External(o1_TEXTPOS);
External(o1_FLASH);
External(o1_PLAYNOTE);
External(o1_STOPNOTE);
External(o1_PLAYTELE);
External(o1_STOPTELE);
External(o1_HIDECURS);
External(o1_SHOWCURS);
External(o1_MUSICBEAT);
External(o1_SCREENLOCK);
External(o1_ADDSPRITE);
External(o1_FREEANIM);
External(o1_DRAWSPRITE);
External(o1_ERASESPRITES);
External(o1_UPDATESPRITES);
External(o1_GETTIMER);
External(o1_SETTIMER);
External(o1_RESETTIMER);
External(o1_ALLOCTIMER);
External(o1_FREETIMER);
External(o1_PALETTELOCK);
External(o1_FONT);
External(o1_DRAWTEXT);
External(o1_HOMETEXT);
External(o1_TEXTRECT);
External(o1_TEXTXY);
External(o1_DROPSHADOW);
External(o1_TEXTCOLOR);
External(o1_OUTLINE);
External(o1_LOADCURSOR);
External(o1_SETGROUND);
External(o1_RESTEXT);
External(o1_ADDMASK);
External(o1_SETMASK);
External(o1_ISSND);
External(o1_STOPSND);
External(o1_PLAYVOICE);
}
#undef External
int16 ScriptFunctionsLgop2::o1_SYSTEM(int16 argc, int16 *argv) {
// This opcode is empty.
return 0;
}
int16 ScriptFunctionsLgop2::o1_INITGRAF(int16 argc, int16 *argv) {
// This opcode is empty.
return 0;
}
int16 ScriptFunctionsLgop2::o1_RESTOREGRAF(int16 argc, int16 *argv) {
// This opcode is empty.
return 0;
}
int16 ScriptFunctionsLgop2::o1_DRAWPIC(int16 argc, int16 *argv) {
return _vm->_screen->drawPic(argv[4], argv[3], argv[2], argv[1], argv[0]);
}
int16 ScriptFunctionsLgop2::o1_CLS(int16 argc, int16 *argv) {
_vm->_screen->clearScreen();
return 0;
}
int16 ScriptFunctionsLgop2::o1_SHOWPAGE(int16 argc, int16 *argv) {
_vm->_screen->show();
return 0;
}
int16 ScriptFunctionsLgop2::o1_EVENT(int16 argc, int16 *argv) {
Common::Event event;
Common::EventManager *eventMan = g_system->getEventManager();
int16 eventNum = 0;
if (eventMan->pollEvent(event)) {
switch (event.type) {
case Common::EVENT_MOUSEMOVE:
_vm->_eventMouseX = event.mouse.x;
_vm->_eventMouseY = event.mouse.y;
break;
case Common::EVENT_LBUTTONDOWN:
eventNum = 1;
break;
/*
case Common::EVENT_LBUTTONUP:
eventNum = 2; // TODO: Is this correct?
break;
*/
case Common::EVENT_RBUTTONDOWN:
eventNum = 3;
break;
/*
case Common::EVENT_RBUTTONUP:
eventNum = 4; // TODO: Is this correct?
break;
*/
case Common::EVENT_KEYDOWN:
_vm->_eventKey = event.kbd.ascii;
eventNum = 5;
break;
case Common::EVENT_QUIT:
// TODO: Exit more gracefully.
g_system->quit();
break;
default:
break;
}
}
_vm->_system->updateScreen();
return eventNum;
}
int16 ScriptFunctionsLgop2::o1_EVENTX(int16 argc, int16 *argv) {
return _vm->_eventMouseX;
}
int16 ScriptFunctionsLgop2::o1_EVENTY(int16 argc, int16 *argv) {
return _vm->_eventMouseY;
}
int16 ScriptFunctionsLgop2::o1_EVENTKEY(int16 argc, int16 *argv) {
return _vm->_eventKey;
}
int16 ScriptFunctionsLgop2::o1_VISUALFX(int16 argc, int16 *argv) {
_vm->_screen->setVisualEffectNum(argv[0]);
return 0;
}
int16 ScriptFunctionsLgop2::o1_PLAYSND(int16 argc, int16 *argv) {
int soundNum = argv[0];
bool loop = false;
if (argc > 1) {
soundNum = argv[1];
loop = (argv[0] == 1);
}
if (soundNum > 0) {
if (!_vm->_mixer->isSoundHandleActive(_audioStreamHandle)) {
_vm->_mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_audioStreamHandle,
_vm->_res->getSound(soundNum)->getAudioStream(_vm->_soundRate, loop));
}
}
return 0;
}
int16 ScriptFunctionsLgop2::o1_PLAYMUS(int16 argc, int16 *argv) {
/*
Disabled for now since MIDI player doesn't support all commands
which results in strange behavior.
int16 musicNum = argv[0];
if (musicNum > 0) {
GenericResource *midi = _vm->_res->getMidi(musicNum);
_vm->_music->playSMF(midi);
_vm->_res->freeResource(midi);
}
*/
return 0;
}
int16 ScriptFunctionsLgop2::o1_STOPMUS(int16 argc, int16 *argv) {
_vm->_music->stop();
return 0;
}
int16 ScriptFunctionsLgop2::o1_ISMUS(int16 argc, int16 *argv) {
if (_vm->_music->isPlaying())
return 1;
else
return 0;
}
int16 ScriptFunctionsLgop2::o1_TEXTPOS(int16 argc, int16 *argv) {
warning("Unimplemented opcode: o1_TEXTPOS");
// This seems to be some kind of low-level opcode.
// The original engine calls int 10h to set the VGA cursor position.
return 0;
}
int16 ScriptFunctionsLgop2::o1_FLASH(int16 argc, int16 *argv) {
_vm->_screen->flash(argv[0]);
return 0;
}
int16 ScriptFunctionsLgop2::o1_PLAYNOTE(int16 argc, int16 *argv) {
warning("Unimplemented opcode: o1_PLAYNOTE");
return 0;
}
int16 ScriptFunctionsLgop2::o1_STOPNOTE(int16 argc, int16 *argv) {
warning("Unimplemented opcode: o1_STOPNOTE");
return 0;
}
int16 ScriptFunctionsLgop2::o1_PLAYTELE(int16 argc, int16 *argv) {
warning("Unimplemented opcode: o1_PLAYTELE");
return 0;
}
int16 ScriptFunctionsLgop2::o1_STOPTELE(int16 argc, int16 *argv) {
warning("Unimplemented opcode: o1_STOPTELE");
return 0;
}
int16 ScriptFunctionsLgop2::o1_HIDECURS(int16 argc, int16 *argv) {
_vm->_system->showMouse(false);
return 0;
}
int16 ScriptFunctionsLgop2::o1_SHOWCURS(int16 argc, int16 *argv) {
_vm->_system->showMouse(true);
return 0;
}
int16 ScriptFunctionsLgop2::o1_MUSICBEAT(int16 argc, int16 *argv) {
warning("Unimplemented opcode: o1_MUSICBEAT");
return 0;
}
int16 ScriptFunctionsLgop2::o1_SCREENLOCK(int16 argc, int16 *argv) {
_vm->_screen->setScreenLock(argv[0] != 0);
return 0;
}
int16 ScriptFunctionsLgop2::o1_ADDSPRITE(int16 argc, int16 *argv) {
//_vm->_screen->drawSprite(argv[2], argv[1], argv[0]);
return argv[2];
}
int16 ScriptFunctionsLgop2::o1_FREEANIM(int16 argc, int16 *argv) {
_vm->_screen->clearChannels();
return 0;
}
int16 ScriptFunctionsLgop2::o1_DRAWSPRITE(int16 argc, int16 *argv) {
return _vm->_screen->drawSprite(argv[2], argv[1], argv[0]);
}
int16 ScriptFunctionsLgop2::o1_ERASESPRITES(int16 argc, int16 *argv) {
_vm->_screen->clearChannels();
return 0;
}
int16 ScriptFunctionsLgop2::o1_UPDATESPRITES(int16 argc, int16 *argv) {
_vm->_screen->updateSprites();
return 0;
}
int16 ScriptFunctionsLgop2::o1_GETTIMER(int16 argc, int16 *argv) {
return _vm->getTimer(argv[0]);
}
int16 ScriptFunctionsLgop2::o1_SETTIMER(int16 argc, int16 *argv) {
_vm->setTimer(argv[1], argv[0]);
return 0;
}
int16 ScriptFunctionsLgop2::o1_RESETTIMER(int16 argc, int16 *argv) {
_vm->resetTimer(argv[0]);
return 0;
}
int16 ScriptFunctionsLgop2::o1_ALLOCTIMER(int16 argc, int16 *argv) {
int16 timerNum = _vm->allocTimer();
return timerNum;
}
int16 ScriptFunctionsLgop2::o1_FREETIMER(int16 argc, int16 *argv) {
_vm->freeTimer(argv[0]);
return 0;
}
int16 ScriptFunctionsLgop2::o1_PALETTELOCK(int16 argc, int16 *argv) {
_vm->_screen->setPaletteLock(argv[0] != 0);
return 0;
}
int16 ScriptFunctionsLgop2::o1_FONT(int16 argc, int16 *argv) {
_vm->_screen->setFont(argv[0]);
return 0;
}
int16 ScriptFunctionsLgop2::o1_DRAWTEXT(int16 argc, int16 *argv) {
// TODO: Needs vsprintf to get the correct text
const char *text = _vm->_dat->getString(argv[argc - 1]);
_vm->_screen->printText(text);
return 0;
}
int16 ScriptFunctionsLgop2::o1_HOMETEXT(int16 argc, int16 *argv) {
warning("Unimplemented opcode: o1_HOMETEXT");
return 0;
}
int16 ScriptFunctionsLgop2::o1_TEXTRECT(int16 argc, int16 *argv) {
int16 x1 = CLIP<int16>(argv[4], 1, 318);
int16 y1 = CLIP<int16>(argv[3], 1, 198);
int16 x2 = CLIP<int16>(argv[2], 1, 318);
int16 y2 = CLIP<int16>(argv[1], 1, 198);
//int16 textValue = argv[0];
// TODO: textValue
_vm->_screen->setTextRect(Common::Rect(x1, y1, x2, y2));
return 0;
}
int16 ScriptFunctionsLgop2::o1_TEXTXY(int16 argc, int16 *argv) {
int16 x = CLIP<int16>(argv[1], 1, 318);
int16 y = CLIP<int16>(argv[0], 1, 198);
_vm->_screen->setTextXY(x, y);
return 0;
}
int16 ScriptFunctionsLgop2::o1_DROPSHADOW(int16 argc, int16 *argv) {
// if the drop shadow color is -1, then text drop shadow is disabled
// when font drop shadow is enabled, outline is disabled
_vm->_screen->setDropShadowColor(argv[0]);
return 0;
}
int16 ScriptFunctionsLgop2::o1_TEXTCOLOR(int16 argc, int16 *argv) {
_vm->_screen->setTextColor(argv[0]);
return 0;
}
int16 ScriptFunctionsLgop2::o1_OUTLINE(int16 argc, int16 *argv) {
// if the outline color is -1, then text outline is disabled
// when font outline is enabled, drop shadow is disabled
_vm->_screen->setOutlineColor(argv[0]);
return 0;
}
int16 ScriptFunctionsLgop2::o1_LOADCURSOR(int16 argc, int16 *argv) {
PictureResource *flex = _vm->_res->getPicture(argv[2]);
Graphics::Surface *surf = flex->getPicture();
CursorMan.replaceCursor((const byte *)surf->pixels, surf->w, surf->h, argv[1], argv[0], 0);
CursorMan.showMouse(true);
_vm->_res->freeResource(flex);
return 0;
}
int16 ScriptFunctionsLgop2::o1_SETGROUND(int16 argc, int16 *argv) {
_vm->_screen->setGround(argv[0]);
return 0;
}
int16 ScriptFunctionsLgop2::o1_RESTEXT(int16 argc, int16 *argv) {
warning("Unimplemented opcode: o1_RESTEXT");
return 0;
}
int16 ScriptFunctionsLgop2::o1_ADDMASK(int16 argc, int16 *argv) {
warning("Unimplemented opcode: o1_ADDMASK");
return 0;
}
int16 ScriptFunctionsLgop2::o1_SETMASK(int16 argc, int16 *argv) {
warning("Unimplemented opcode: o1_SETMASK");
return 0;
}
int16 ScriptFunctionsLgop2::o1_ISSND(int16 argc, int16 *argv) {
if (_vm->_mixer->isSoundHandleActive(_audioStreamHandle))
return 1;
else
return 0;
}
int16 ScriptFunctionsLgop2::o1_STOPSND(int16 argc, int16 *argv) {
_vm->_mixer->stopHandle(_audioStreamHandle);
return 0;
}
int16 ScriptFunctionsLgop2::o1_PLAYVOICE(int16 argc, int16 *argv) {
if (argv[0] > 0) {
_vm->_mixer->stopHandle(_audioStreamHandle);
_vm->_mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_audioStreamHandle,
_vm->_res->getSound(argv[0])->getAudioStream(_vm->_soundRate, false));
}
return 0;
}
} // End of namespace Made
|