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
|
/* 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 "made/made.h"
#include "made/screen.h"
#include "made/resource.h"
namespace Made {
Screen::Screen(MadeEngine *vm) : _vm(vm) {
_screen1 = new Graphics::Surface();
_screen1->create(320, 200, 1);
_screen2 = new Graphics::Surface();
_screen2->create(320, 200, 1);
_clipInfo1.x = _clipInfo2.x = 0;
_clipInfo1.y = _clipInfo2.y = 0;
_clipInfo1.w = _clipInfo2.w = 320;
_clipInfo1.h = _clipInfo2.h = 200;
_clipInfo1.destSurface = _screen1;
_clipInfo2.destSurface = _screen2;
_clipArea.destSurface = _screen2;
for (int i = 0; i <= 3; i++)
_excludeClipAreaEnabled[i] = false;
_screenLock = false;
_paletteLock = false;
clearChannels();
}
Screen::~Screen() {
delete _screen1;
delete _screen2;
}
void Screen::clearScreen() {
_screen1->fillRect(Common::Rect(0, 0, 320, 200), 0);
_screen2->fillRect(Common::Rect(0, 0, 320, 200), 0);
//_vm->_system->clearScreen();
}
void Screen::drawSurface(Graphics::Surface *source, int x, int y) {
}
void Screen::loadRGBPalette(byte *palRGB, int count) {
for (int i = 0; i < count; i++) {
_screenPalette[i * 4 + 0] = palRGB[i * 3 + 0];
_screenPalette[i * 4 + 1] = palRGB[i * 3 + 1];
_screenPalette[i * 4 + 2] = palRGB[i * 3 + 2];
_screenPalette[i * 4 + 3] = 0;
}
}
void Screen::setRGBPalette(byte *palRGB, int start, int count) {
loadRGBPalette(palRGB, count);
_vm->_system->setPalette(_screenPalette, start, count);
}
uint16 Screen::updateChannel(uint16 channelIndex) {
return 0;
}
void Screen::deleteChannel(uint16 channelIndex) {
if (channelIndex < 1 || channelIndex >= 100)
return;
_channels[channelIndex - 1].type = 0;
_channels[channelIndex - 1].state = 0;
_channels[channelIndex - 1].index = 0;
}
int16 Screen::getChannelType(uint16 channelIndex) {
if (channelIndex < 1 || channelIndex >= 100)
return -1;
return _channels[channelIndex - 1].type;
}
int16 Screen::getChannelState(uint16 channelIndex) {
if (channelIndex < 1 || channelIndex >= 100)
return -1;
return _channels[channelIndex - 1].state;
}
void Screen::setChannelState(uint16 channelIndex, int16 state) {
if (channelIndex < 1 || channelIndex >= 100 || _channels[channelIndex - 1].type == 0)
return;
_channels[channelIndex - 1].state = state;
}
uint16 Screen::setChannelLocation(uint16 channelIndex, int16 x, int16 y) {
if (channelIndex < 1 || channelIndex >= 100 || _channels[channelIndex - 1].type == 0)
return 0;
_channels[channelIndex - 1].x = x;
_channels[channelIndex - 1].y = y;
return updateChannel(channelIndex - 1) + 1;
}
uint16 Screen::setChannelContent(uint16 channelIndex, uint16 index) {
if (channelIndex < 1 || channelIndex >= 100 || _channels[channelIndex - 1].type == 0)
return 0;
//debug(2, "setChannelContent(%d, %04X)\n", channelIndex, index); fflush(stdout); g_system->delayMillis(5000);
_channels[channelIndex - 1].index = index;
return updateChannel(channelIndex - 1) + 1;
}
void Screen::drawSpriteChannels(const ClipInfo &clipInfo, int16 includeStateMask, int16 excludeStateMask) {
for (int i = 0; i <= 3; i++)
_excludeClipArea[i].destSurface = clipInfo.destSurface;
_clipArea.destSurface = clipInfo.destSurface;
for (uint16 i = 0; i < _channelsUsedCount; i++) {
debug(2, "drawSpriteChannels() i = %d\n", i);
if (((_channels[i].state & includeStateMask) == includeStateMask) && (_channels[i].state & excludeStateMask) == 0) {
uint16 flag1 = _channels[i].state & 0x10;
uint16 flag2 = _channels[i].state & 0x20;
debug(2, "drawSpriteChannels() type = %d; index = %04X\n", _channels[i].type, _channels[i].index);
switch (_channels[i].type) {
case 1: // drawFlex
if (_channels[i].state & 4) {
drawFlex(_channels[i].index, _channels[i].x, _channels[i].y, flag1, flag2, _clipArea);
} else if (_channels[i].state & 8) {
for (int excludeIndex = 0; excludeIndex < 4; excludeIndex++) {
if (_excludeClipAreaEnabled[excludeIndex]) {
drawFlex(_channels[i].index, _channels[i].x, _channels[i].y, flag1, flag2, _excludeClipArea[excludeIndex]);
}
}
} else {
drawFlex(_channels[i].index, _channels[i].x, _channels[i].y, flag1, flag2, clipInfo);
}
break;
case 2: // drawObjectText
// TODO
break;
case 3: // drawAnimFrame
if (_channels[i].state & 4) {
drawAnimFrame(_channels[i].index, _channels[i].x, _channels[i].y, _channels[i].frameNum, flag1, flag2, _clipArea);
} else if (_channels[i].state & 8) {
for (int excludeIndex = 0; excludeIndex < 4; excludeIndex++) {
if (_excludeClipAreaEnabled[excludeIndex]) {
drawAnimFrame(_channels[i].index, _channels[i].x, _channels[i].y, _channels[i].frameNum, flag1, flag2, _excludeClipArea[excludeIndex]);
}
}
} else {
drawAnimFrame(_channels[i].index, _channels[i].x, _channels[i].y, _channels[i].frameNum, flag1, flag2, clipInfo);
}
break;
case 4: // drawMenuText
// TODO
break;
default:
break;
}
}
}
}
void Screen::updateSprites() {
// TODO: This needs some more work, dirty rectangles are currently not used
memcpy(_screen2->pixels, _screen1->pixels, 64000);
//drawSpriteChannels(_clipInfo1, 3, 0x40);//CHECKME
drawSpriteChannels(_clipInfo1, 3, 0);//CHECKME
drawSpriteChannels(_clipInfo2, 1, 2);//CHECKME
_vm->_system->copyRectToScreen((const byte*)_screen2->pixels, _screen2->pitch, 0, 0, _screen2->w, _screen2->h);
}
void Screen::clearChannels() {
for (uint16 i = 0; i < ARRAYSIZE(_channels); i++) {
_channels[i].type = 0;
_channels[i].index = 0;
}
_channelsUsedCount = 0;
}
uint16 Screen::drawFlex(uint16 flexIndex, int16 x, int16 y, uint16 flag1, uint16 flag2, const ClipInfo &clipInfo) {
if (flexIndex == 0)
return 0;
if (flexIndex == 1279) return 0; // HACK: fixes the first screen
PictureResource *flex = _vm->_res->getPicture(flexIndex);
Graphics::Surface *sourceSurface = flex->getPicture();
byte *source = (byte*)sourceSurface->getBasePtr(0, 0);
byte *dest = (byte*)clipInfo.destSurface->getBasePtr(x, y);
if (x + sourceSurface->w > clipInfo.destSurface->w || y + sourceSurface->h > clipInfo.destSurface->h) {
debug(2, "CLIPPING PROBLEM: x = %d; y = %d; w = %d; h = %d; x+w = %d; y+h = %d\n",
x, y, sourceSurface->w, sourceSurface->h, x + sourceSurface->w, y + sourceSurface->h);
//fflush(stdout); g_system->delayMillis(5000);
return 0;
}
for (int16 yc = 0; yc < sourceSurface->h; yc++) {
for (int16 xc = 0; xc < sourceSurface->w; xc++) {
if (source[xc])
dest[xc] = source[xc];
}
source += sourceSurface->pitch;
dest += clipInfo.destSurface->pitch;
}
// Palette is set in showPage
if (flex->hasPalette()) {
byte *pal = flex->getPalette();
if (pal != 0) {
loadRGBPalette(pal);
}
}
_vm->_res->freeResource(flex);
return 0;
}
void Screen::drawAnimFrame(uint16 animIndex, int16 x, int16 y, int16 frameNum, uint16 flag1, uint16 flag2, const ClipInfo &clipInfo) {
if (frameNum < 0)
return;
AnimationResource *anim = _vm->_res->getAnimation(animIndex);
Graphics::Surface *sourceSurface = anim->getFrame(frameNum);
byte *source = (byte*)sourceSurface->getBasePtr(0, 0);
byte *dest = (byte*)clipInfo.destSurface->getBasePtr(x, y);
for (int16 yc = 0; yc < sourceSurface->h; yc++) {
for (int16 xc = 0; xc < sourceSurface->w; xc++) {
if (source[xc])
dest[xc] = source[xc];
}
source += sourceSurface->pitch;
dest += clipInfo.destSurface->pitch;
}
_vm->_res->freeResource(anim);
}
uint16 Screen::drawPic(uint16 index, int16 x, int16 y, uint16 flag1, uint16 flag2) {
//HACK (until clipping is impelemented)
if (y > 200) y = 0;
drawFlex(index, x, y, flag1, flag2, _clipInfo1);
return 0;
}
uint16 Screen::drawAnimPic(uint16 animIndex, int16 x, int16 y, int16 frameNum, uint16 flag1, uint16 flag2) {
drawAnimFrame(animIndex, x, y, frameNum, flag1, flag2, _clipInfo1);
return 0;
}
void Screen::addSprite(uint16 spriteIndex) {
bool oldScreenLock = _screenLock;
drawFlex(spriteIndex, 0, 0, 0, 0, _clipInfo1);
_screenLock = oldScreenLock;
}
uint16 Screen::drawSprite(uint16 flexIndex, int16 x, int16 y) {
return placeSprite(_channelsUsedCount + 1, flexIndex, x, y);
}
uint16 Screen::placeSprite(uint16 channelIndex, uint16 flexIndex, int16 x, int16 y) {
debug(2, "placeSprite(%d, %04X, %d, %d)\n", channelIndex, flexIndex, x, y); fflush(stdout);
//g_system->delayMillis(5000);
if (channelIndex < 1 || channelIndex >= 100)
return 0;
channelIndex--;
PictureResource *flex = _vm->_res->getPicture(flexIndex);
if (flex) {
Graphics::Surface *surf = flex->getPicture();
int16 state = 1;
int16 x1, y1, x2, y2;
x1 = x;
y1 = y;
x2 = x + surf->w + 1;
y2 = y + surf->h + 1;
//TODO: clipRect(x1, y1, x2, y2);
if (_ground == 0)
state |= 2;
if (_clip != 0)
state |= 4;
if (_exclude != 0)
state |= 8;
_channels[channelIndex].state = state;
_channels[channelIndex].type = 1;
_channels[channelIndex].index = flexIndex;
_channels[channelIndex].x = x;
_channels[channelIndex].y = y;
_channels[channelIndex].x1 = x1;
_channels[channelIndex].y1 = y1;
_channels[channelIndex].x2 = x2;
_channels[channelIndex].y2 = y2;
_channels[channelIndex].area = (x2 - x2) * (y2 - y1);
if (_channelsUsedCount <= channelIndex)
_channelsUsedCount = channelIndex + 1;
_vm->_res->freeResource(flex);
} else {
_channels[channelIndex].type = 0;
_channels[channelIndex].state = 0;
}
return channelIndex + 1;
}
uint16 Screen::placeAnim(uint16 channelIndex, uint16 animIndex, int16 x, int16 y, int16 frameNum) {
if (channelIndex < 1 || channelIndex >= 100)
return 0;
channelIndex--;
AnimationResource *anim = _vm->_res->getAnimation(animIndex);
if (anim) {
int16 state = 1;
int16 x1, y1, x2, y2;
x1 = x;
y1 = y;
x2 = x + anim->getWidth();
y2 = y + anim->getHeight();
//TODO: clipRect(x1, y1, x2, y2);
if (anim->getFlags() == 1 || _ground == 0)
state |= 2;
if (_clip != 0)
state |= 4;
if (_exclude != 0)
state |= 8;
_channels[channelIndex].state = state;
_channels[channelIndex].type = 3;
_channels[channelIndex].index = animIndex;
_channels[channelIndex].frameNum = frameNum;
_channels[channelIndex].needRefresh = 1;
_channels[channelIndex].x = x;
_channels[channelIndex].y = y;
_channels[channelIndex].x1 = x1;
_channels[channelIndex].y1 = y1;
_channels[channelIndex].x2 = x2;
_channels[channelIndex].y2 = y2;
_channels[channelIndex].area = (x2 - x2) * (y2 - y1);
if (_channelsUsedCount <= channelIndex)
_channelsUsedCount = channelIndex + 1;
_vm->_res->freeResource(anim);
} else {
_channels[channelIndex].type = 0;
_channels[channelIndex].state = 0;
}
return channelIndex + 1;
}
int16 Screen::setAnimFrame(uint16 channelIndex, int16 frameNum) {
if (channelIndex < 1 || channelIndex >= 100 || _channels[channelIndex - 1].type == 0)
return 0;
channelIndex--;
_channels[channelIndex].frameNum = frameNum;
_channels[channelIndex].needRefresh = 1;
return updateChannel(channelIndex) + 1;
}
int16 Screen::getAnimFrame(uint16 channelIndex) {
if (channelIndex < 1 || channelIndex >= 100 || _channels[channelIndex - 1].type == 0)
return -1;
return _channels[channelIndex - 1].frameNum;
}
int16 Screen::getAnimFrameCount(uint16 animIndex) {
int16 frameCount = 0;
AnimationResource *anim = _vm->_res->getAnimation(animIndex);
if (anim) {
frameCount = anim->getCount();
_vm->_res->freeResource(anim);
}
return frameCount;
}
uint16 Screen::placeText(uint16 channelIndex, uint16 textObjectIndex, int16 x, int16 y, uint16 fontNum, int16 textColor, int16 outlineColor) {
return 0;
}
void Screen::show() {
// TODO
memcpy(_screen2->pixels, _screen1->pixels, 64000);
drawSpriteChannels(_clipInfo2, 0, 0);
//drawSpriteChannels(_clipInfo2, 3, 0);//CHECKME
//drawSpriteChannels(_clipInfo2, 1, 2);//CHECKME
//_vm->_system->copyRectToScreen((const byte*)_screen1->pixels, _screen1->pitch, 0, 0, _screen1->w, _screen1->h);
_vm->_system->copyRectToScreen((const byte*)_screen2->pixels, _screen2->pitch, 0, 0, _screen2->w, _screen2->h);
}
} // End of namespace Made
|