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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
|
/* 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 "graphics/iff.h"
#include "parallaction/parallaction.h"
namespace Parallaction {
struct Sprite {
uint16 size;
uint16 x;
uint16 y;
uint16 w;
uint16 h;
byte *packedData;
Sprite() : size(0), x(0), y(0), w(0), h(0), packedData(0) {
}
~Sprite() {
free(packedData);
}
};
struct Sprites : public Frames {
uint16 _num;
Sprite* _sprites;
Sprites(uint num) {
_num = num;
_sprites = new Sprite[_num];
}
~Sprites() {
delete _sprites;
}
uint16 getNum() {
return _num;
}
byte* getData(uint16 index) {
assert(index < _num);
return _sprites[index].packedData;
}
void getRect(uint16 index, Common::Rect &r) {
assert(index < _num);
r.setWidth(_sprites[index].w);
r.setHeight(_sprites[index].h);
r.moveTo(_sprites[index].x, _sprites[index].y);
}
uint getRawSize(uint16 index) {
assert(index < _num);
return _sprites[index].size;
}
uint getSize(uint16 index) {
assert(index < _num);
return _sprites[index].w * _sprites[index].h;
}
};
void DosDisk_br::errorFileNotFound(const char *s) {
error("File '%s' not found", s);
}
Common::String DosDisk_br::selectArchive(const Common::String& name) {
debugC(5, kDebugDisk, "DosDisk_br::selectArchive");
Common::String oldPath(_partPath);
strcpy(_partPath, name.c_str());
return oldPath;
}
void DosDisk_br::setLanguage(uint16 language) {
debugC(5, kDebugDisk, "DosDisk_br::setLanguage");
switch (language) {
case 0:
strcpy(_languageDir, "it");
break;
case 1:
strcpy(_languageDir, "fr");
break;
case 2:
strcpy(_languageDir, "en");
break;
case 3:
strcpy(_languageDir, "ge");
break;
default:
error("unknown language");
}
return;
}
DosDisk_br::DosDisk_br(Parallaction* vm) : _vm(vm) {
}
DosDisk_br::~DosDisk_br() {
}
Frames* DosDisk_br::loadTalk(const char *name) {
debugC(5, kDebugDisk, "DosDisk_br::loadTalk");
char path[PATH_LEN];
sprintf(path, "%s/tal/%s.tal", _partPath, name);
return createSprites(path);
}
Script* DosDisk_br::loadLocation(const char *name) {
debugC(5, kDebugDisk, "DosDisk_br::loadLocation");
Common::File *stream = new Common::File;
char path[PATH_LEN];
sprintf(path, "%s/%s/%s.slf", _partPath, _languageDir, name);
if (!stream->open(path)) {
sprintf(path, "%s/%s/%s.loc", _partPath, _languageDir, name);
if (!stream->open(path))
errorFileNotFound(path);
}
return new Script(stream, true);
}
Script* DosDisk_br::loadScript(const char* name) {
debugC(5, kDebugDisk, "DosDisk_br::loadScript");
Common::File *stream = new Common::File;
char path[PATH_LEN];
sprintf(path, "%s/scripts/%s.scr", _partPath, name);
if (!stream->open(path))
errorFileNotFound(path);
return new Script(stream, true);
}
// there are no Head resources in Big Red Adventure
Frames* DosDisk_br::loadHead(const char* name) {
debugC(5, kDebugDisk, "DosDisk_br::loadHead");
return 0;
}
void DosDisk_br::loadBitmap(Common::SeekableReadStream &stream, Graphics::Surface &surf, byte *palette) {
stream.skip(4);
uint width = stream.readUint32BE();
uint height = stream.readUint32BE();
stream.skip(20);
if (palette) {
stream.read(palette, 768);
} else {
stream.skip(768);
}
surf.create(width, height, 1);
stream.read(surf.pixels, width * height);
}
Frames* DosDisk_br::loadPointer(const char *name) {
debugC(5, kDebugDisk, "DosDisk_br::loadPointer");
char path[PATH_LEN];
sprintf(path, "%s.ras", name);
Common::File stream;
if (!stream.open(path))
errorFileNotFound(path);
Graphics::Surface *surf = new Graphics::Surface;
loadBitmap(stream, *surf, 0);
return new SurfaceToFrames(surf);
}
Font* DosDisk_br::loadFont(const char* name) {
debugC(5, kDebugDisk, "DosDisk_br::loadFont");
char path[PATH_LEN];
sprintf(path, "%s.fnt", name);
Common::File stream;
if (!stream.open(path))
errorFileNotFound(path);
return createFont(name, stream);
}
Frames* DosDisk_br::loadObjects(const char *name) {
debugC(5, kDebugDisk, "DosDisk_br::loadObjects");
return 0;
}
void genSlidePath(char *path, const char* name) {
sprintf(path, "%s.bmp", name);
}
Frames* DosDisk_br::loadStatic(const char* name) {
debugC(5, kDebugDisk, "DosDisk_br::loadStatic");
char path[PATH_LEN];
sprintf(path, "%s/ras/%s", _partPath, name);
Common::File stream;
if (!stream.open(path)) {
errorFileNotFound(path);
}
Graphics::Surface *surf = new Graphics::Surface;
loadBitmap(stream, *surf, 0);
return new SurfaceToFrames(surf);
}
Sprites* DosDisk_br::createSprites(const char *path) {
Common::File stream;
if (!stream.open(path)) {
errorFileNotFound(path);
}
uint16 num = stream.readUint16LE();
Sprites *sprites = new Sprites(num);
for (uint i = 0; i < num; i++) {
Sprite *spr = &sprites->_sprites[i];
spr->size = stream.readUint16LE();
spr->x = stream.readUint16LE();
spr->y = stream.readUint16LE();
spr->w = stream.readUint16LE();
spr->h = stream.readUint16LE();
spr->packedData = (byte*)malloc(spr->size);
stream.read(spr->packedData, spr->size);
}
return sprites;
}
Frames* DosDisk_br::loadFrames(const char* name) {
debugC(5, kDebugDisk, "DosDisk_br::loadFrames");
char path[PATH_LEN];
sprintf(path, "%s/ani/%s", _partPath, name);
return createSprites(path);
}
// Slides in Nippon Safes are basically screen-sized pictures with valid
// palette data used for menu and for location switches. Big Red Adventure
// doesn't need slides in that sense, but it still has some special
// graphics resources with palette data, so those will be named slides.
//
void DosDisk_br::loadSlide(BackgroundInfo& info, const char *name) {
debugC(5, kDebugDisk, "DosDisk_br::loadSlide");
char path[PATH_LEN];
genSlidePath(path, name);
Common::File stream;
if (!stream.open(path))
errorFileNotFound(path);
byte rgb[768];
loadBitmap(stream, info.bg, rgb);
info.width = info.bg.w;
info.height = info.bg.h;
for (uint i = 0; i < 256; i++) {
info.palette.setEntry(i, rgb[i] >> 2, rgb[i+256] >> 2, rgb[i+512] >> 2);
}
return;
}
void DosDisk_br::loadScenery(BackgroundInfo& info, const char *name, const char *mask, const char* path) {
debugC(5, kDebugDisk, "DosDisk_br::loadScenery");
char filename[PATH_LEN];
Common::File stream;
if (name) {
sprintf(filename, "%s/bkg/%s.bkg", _partPath, name);
if (!stream.open(filename))
errorFileNotFound(filename);
byte rgb[768];
loadBitmap(stream, info.bg, rgb);
info.width = info.bg.w;
info.height = info.bg.h;
for (uint i = 0; i < 256; i++) {
info.palette.setEntry(i, rgb[i] >> 2, rgb[i+256] >> 2, rgb[i+512] >> 2);
}
stream.close();
}
if (mask) {
sprintf(filename, "%s/msk/%s.msk", _partPath, mask);
if (!stream.open(filename))
errorFileNotFound(filename);
// NOTE: info.width and info.height are only valid if the background graphics
// have already been loaded
info.mask.create(info.width, info.height);
info.mask.bigEndian = false;
stream.read(info.mask.data, info.mask.size);
stream.close();
}
if (path) {
sprintf(filename, "%s/pth/%s.pth", _partPath, path);
if (!stream.open(filename))
errorFileNotFound(filename);
// NOTE: info.width and info.height are only valid if the background graphics
// have already been loaded
info.path.create(info.width, info.height);
stream.read(info.path.data, info.path.size);
stream.close();
}
return;
}
Table* DosDisk_br::loadTable(const char* name) {
debugC(5, kDebugDisk, "DosDisk_br::loadTable");
char path[PATH_LEN];
sprintf(path, "%s/%s.tab", _partPath, name);
Common::File stream;
if (!stream.open(path))
errorFileNotFound(path);
Table *t = createTableFromStream(100, stream);
stream.close();
return t;
}
Common::SeekableReadStream* DosDisk_br::loadMusic(const char* name) {
debugC(5, kDebugDisk, "DosDisk_br::loadMusic");
return 0;
}
Common::ReadStream* DosDisk_br::loadSound(const char* name) {
debugC(5, kDebugDisk, "DosDisk_br::loadSound");
return 0;
}
AmigaDisk_br::AmigaDisk_br(Parallaction *vm) : DosDisk_br(vm) {
}
AmigaDisk_br::~AmigaDisk_br() {
}
/*
FIXME: mask values are not computed correctly for level 1 and 2
NOTE: this routine is only able to build masks for Nippon Safes, since mask widths are hardcoded
into the main loop.
*/
void buildMask2(byte* buf) {
byte mask1[16] = { 0, 0x80, 0x20, 0xA0, 8, 0x88, 0x28, 0xA8, 2, 0x82, 0x22, 0xA2, 0xA, 0x8A, 0x2A, 0xAA };
byte mask0[16] = { 0, 0x40, 0x10, 0x50, 4, 0x44, 0x14, 0x54, 1, 0x41, 0x11, 0x51, 0x5, 0x45, 0x15, 0x55 };
byte plane0[40];
byte plane1[40];
for (int32 i = 0; i < _vm->_screenHeight; i++) {
memcpy(plane0, buf, 40);
memcpy(plane1, buf+40, 40);
for (uint32 j = 0; j < 40; j++) {
*buf++ = mask0[(plane0[j] & 0xF0) >> 4] | mask1[(plane1[j] & 0xF0) >> 4];
*buf++ = mask0[plane0[j] & 0xF] | mask1[plane1[j] & 0xF];
}
}
}
void AmigaDisk_br::loadBackground(BackgroundInfo& info, const char *name) {
char path[PATH_LEN];
sprintf(path, "%s", name);
Common::File s;
if (!s.open(path))
errorFileNotFound(path);
byte *pal;
Graphics::ILBMDecoder decoder(s, info.bg, pal);
decoder.decode();
uint i;
info.width = info.bg.w;
info.height = info.bg.h;
byte *p = pal;
for (i = 0; i < 16; i++) {
byte r = *p >> 2;
p++;
byte g = *p >> 2;
p++;
byte b = *p >> 2;
p++;
info.palette.setEntry(i, r, g, b);
}
free(pal);
return;
}
void AmigaDisk_br::loadMask(BackgroundInfo& info, const char *name) {
debugC(5, kDebugDisk, "AmigaDisk_br::loadMask(%s)", name);
Common::File s;
if (!s.open(name))
return;
s.seek(0x30, SEEK_SET);
byte r, g, b;
for (uint i = 0; i < 4; i++) {
r = s.readByte();
g = s.readByte();
b = s.readByte();
info.layers[i] = (((r << 4) & 0xF00) | (g & 0xF0) | (b >> 4)) & 0xFF;
}
s.seek(0x126, SEEK_SET); // HACK: skipping IFF/ILBM header should be done by analysis, not magic
Graphics::PackBitsReadStream stream(s);
info.mask.create(info.width, info.height);
stream.read(info.mask.data, info.mask.size);
buildMask2(info.mask.data);
return;
}
void AmigaDisk_br::loadScenery(BackgroundInfo& info, const char* name, const char* mask, const char* path) {
debugC(1, kDebugDisk, "AmigaDisk_br::loadScenery '%s', '%s' '%s'", name, mask, path);
char filename[PATH_LEN];
Common::File stream;
if (name) {
sprintf(filename, "%s/backs/%s.bkg", _partPath, name);
loadBackground(info, filename);
}
if (mask) {
sprintf(filename, "%s/msk/%s.msk", _partPath, name);
loadMask(info, filename);
}
if (path) {
sprintf(filename, "%s/pth/%s.pth", _partPath, path);
if (!stream.open(filename))
errorFileNotFound(filename);
// NOTE: info.width and info.height are only valid if the background graphics
// have already been loaded
info.path.create(info.width, info.height);
stream.read(info.path.data, info.path.size);
stream.close();
}
return;
}
void AmigaDisk_br::loadSlide(BackgroundInfo& info, const char *name) {
debugC(1, kDebugDisk, "AmigaDisk_br::loadSlide '%s'", name);
char path[PATH_LEN];
sprintf(path, "backs/%s.bkg", name);
loadBackground(info, path);
return;
}
Frames* AmigaDisk_br::loadStatic(const char* name) {
debugC(1, kDebugDisk, "AmigaDisk_br::loadStatic '%s'", name);
char path[PATH_LEN];
sprintf(path, "%s/ras/%s", _partPath, name);
Common::File stream;
if (!stream.open(path)) {
errorFileNotFound(path);
}
byte *pal = 0;
Graphics::Surface* surf = new Graphics::Surface;
Graphics::ILBMDecoder decoder(stream, *surf, pal);
decoder.decode();
free(pal);
return new SurfaceToFrames(surf);
}
Sprites* AmigaDisk_br::createSprites(const char *path) {
Common::File stream;
if (!stream.open(path)) {
errorFileNotFound(path);
}
uint16 num = stream.readUint16BE();
Sprites *sprites = new Sprites(num);
for (uint i = 0; i < num; i++) {
Sprite *spr = &sprites->_sprites[i];
spr->size = stream.readUint16BE();
spr->x = stream.readUint16BE();
spr->y = stream.readUint16BE();
spr->w = stream.readUint16BE();
spr->h = stream.readUint16BE();
// TODO: Convert image format
spr->packedData = (byte*)malloc(spr->size);
stream.read(spr->packedData, spr->size);
}
return sprites;
}
Frames* AmigaDisk_br::loadFrames(const char* name) {
debugC(1, kDebugDisk, "AmigaDisk_br::loadFrames '%s'", name);
char path[PATH_LEN];
sprintf(path, "%s/anims/%s", _partPath, name);
return createSprites(path);
}
Frames* AmigaDisk_br::loadTalk(const char *name) {
debugC(1, kDebugDisk, "AmigaDisk_br::loadTalk '%s'", name);
char path[PATH_LEN];
sprintf(path, "%s/talks/%s.tal", _partPath, name);
return createSprites(path);
}
Font* AmigaDisk_br::loadFont(const char* name) {
debugC(1, kDebugDisk, "AmigaFullDisk::loadFont '%s'", name);
char path[PATH_LEN];
sprintf(path, "%s", name);
Common::File stream;
if (!stream.open(path))
errorFileNotFound(path);
return createFont(name, stream);
}
} // namespace Parallaction
|