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
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
|
/* 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.
*
*/
#include "voyeur/files.h"
#include "voyeur/graphics.h"
#include "voyeur/voyeur.h"
namespace Voyeur {
#define BOLT_GROUP_SIZE 16
BoltFilesState::BoltFilesState() {
_curLibPtr = NULL;
_curGroupPtr = NULL;
_curMemberPtr = NULL;
_curMemInfoPtr = NULL;
_fromGroupFlag = 0;
_xorMask = 0;
_encrypt = false;
_curFilePosition = 0;
_bufferEnd = 0;
_bufferBegin = 0;
_bytesLeft = 0;
_bufSize = 0;
_bufStart = NULL;
_bufPos = NULL;
_historyIndex = 0;
_runLength = 0;
_decompState = 0;
_runType = 0;
_runValue = 0;
_runOffset = 0;
Common::fill(&_historyBuffer[0], &_historyBuffer[0x200], 0);
_curFd = NULL;
_boltPageFrame = NULL;
}
#define NEXT_BYTE if (--_bytesLeft < 0) nextBlock()
byte *BoltFilesState::decompress(byte *buf, int size, int mode) {
if (!buf) {
buf = new byte[size];
Common::fill(buf, buf + size, 0);
}
byte *bufP = buf;
if (mode & 8) {
_decompState = 1;
_runType = 0;
_runLength = size;
}
while (size > 0) {
if (!_decompState) {
NEXT_BYTE;
byte nextByte = *_bufPos++;
switch (nextByte & 0xC0) {
case 0:
_runType = 0;
_runLength = 30 - (nextByte & 0x1f) + 1;
break;
case 0x40:
_runType = 1;
_runLength = 35 - (nextByte & 0x1f);
NEXT_BYTE;
_runOffset = *_bufPos++ + ((nextByte & 0x20) << 3);
break;
case 0x80:
_runType = 1;
_runLength = (nextByte & 0x20) ? ((32 - (nextByte & 0x1f)) << 2) + 2 :
(32 - (nextByte & 0x1f)) << 2;
NEXT_BYTE;
_runOffset = *_bufPos++ << 1;
break;
default:
_runType = 2;
if (nextByte & 0x20) {
_runLength = 0;
} else {
NEXT_BYTE;
_runLength = ((32 - (nextByte & 0x1f)) + (*_bufPos++ << 5)) << 2;
NEXT_BYTE;
_bufPos++;
NEXT_BYTE;
_runValue = *_bufPos++;
}
break;
}
_runOffset = _historyIndex - _runOffset;
}
int runOffset = _runOffset & 0x1ff;
int len;
if (_runLength <= size) {
len = _runLength;
_decompState = 0;
} else {
_decompState = 1;
len = size;
_runLength -= size;
if (_runType == 1)
_runOffset += len;
}
// Reduce the remaining size
size -= len;
// Handle the run lengths
switch (_runType) {
case 0:
while (len-- > 0) {
NEXT_BYTE;
byte v = *_bufPos++;
_historyBuffer[_historyIndex] = v;
*bufP++ = v;
_historyIndex = (_historyIndex + 1) & 0x1ff;
}
break;
case 1:
while (len-- > 0) {
_historyBuffer[_historyIndex] = _historyBuffer[runOffset];
*bufP++ = _historyBuffer[runOffset];
_historyIndex = (_historyIndex + 1) & 0x1ff;
runOffset = (runOffset + 1) & 0x1ff;
}
break;
default:
while (len-- > 0) {
_historyBuffer[_historyIndex] = _runValue;
*bufP++ = _runValue;
_historyIndex = (_historyIndex + 1) & 0x1ff;
}
break;
}
}
return buf;
}
#undef NEXT_BYTE
void BoltFilesState::nextBlock() {
if (_curFilePosition != _bufferEnd)
_curFd->seek(_bufferEnd);
_bufferBegin = _bufferEnd;
int bytesRead = _curFd->read(_bufStart, _bufSize);
_bufferEnd = _curFilePosition = _bufferBegin + bytesRead;
_bytesLeft = bytesRead - 1;
_bufPos = _bufStart;
}
/*------------------------------------------------------------------------*/
FilesManager::FilesManager() {
_decompressSize = 0x7000;
}
bool FilesManager::openBoltLib(const Common::String &filename, BoltFile *&boltFile) {
if (boltFile != NULL) {
_boltFilesState._curLibPtr = boltFile;
return true;
}
// Create the bolt file interface object and load the index
if (filename == "bvoy.blt")
boltFile = _boltFilesState._curLibPtr = new BVoyBoltFile(_boltFilesState);
else if (filename == "stampblt.blt")
boltFile = _boltFilesState._curLibPtr = new StampBoltFile(_boltFilesState);
else
error("Unknown bolt file specified");
return true;
}
byte *FilesManager::fload(const Common::String &filename, int *size) {
Common::File f;
int filesize;
byte *data = NULL;
if (f.open(filename)) {
// Read in the file
filesize = f.size();
data = new byte[filesize];
f.read(data, filesize);
} else {
filesize = 0;
}
if (size)
*size = filesize;
return data;
}
/*------------------------------------------------------------------------*/
BoltFile::BoltFile(const Common::String &filename, BoltFilesState &state): _state(state) {
_state._curFd = &_file;
if (!_file.open(filename))
error("Could not open %s", filename.c_str());
_state._curFilePosition = 0;
// Read in the file header
byte header[16];
_file.read(&header[0], 16);
if (strncmp((const char *)&header[0], "BOLT", 4) != 0)
error("Tried to load non-bolt file");
int totalGroups = header[11] ? header[11] : 0x100;
for (int i = 0; i < totalGroups; ++i)
_groups.push_back(BoltGroup(_state._curFd));
}
BoltFile::~BoltFile() {
_file.close();
if (_state._curFd == &_file)
_state._curFd = NULL;
}
bool BoltFile::getBoltGroup(uint32 id) {
++_state._fromGroupFlag;
_state._curLibPtr = this;
_state._curGroupPtr = &_groups[(id >> 8) & 0xff];
if (!_state._curGroupPtr->_loaded) {
// Load the group index
_state._curGroupPtr->load();
}
if (_state._curGroupPtr->_callInitGro)
initGro();
if ((id >> 16) != 0) {
id &= 0xff00;
for (int idx = 0; idx < _state._curGroupPtr->_count; ++idx, ++id) {
byte *member = getBoltMember(id);
assert(member);
}
} else if (!_state._curGroupPtr->_processed) {
_state._curGroupPtr->_processed = true;
_state._curGroupPtr->load();
}
resolveAll();
--_state._fromGroupFlag;
return true;
}
void BoltFile::freeBoltGroup(uint32 id) {
_state._curLibPtr = this;
_state._curGroupPtr = &_groups[(id >> 8) & 0xff];
// Unload the group
_state._curGroupPtr->unload();
}
void BoltFile::freeBoltMember(uint32 id) {
// TODO: Determine whether this is needed
warning("TODO: BoltFile::freeBoltMember");
}
BoltEntry &BoltFile::getBoltEntryFromLong(uint32 id) {
BoltGroup &group = _groups[id >> 24];
assert(group._loaded);
BoltEntry &entry = group._entries[(id >> 16) & 0xff];
assert(!entry.hasResource() || (id & 0xffff) == 0);
return entry;
}
BoltEntry &BoltFile::boltEntry(uint16 id) {
BoltGroup &group = _groups[id >> 8];
assert(group._loaded);
BoltEntry &entry = group._entries[id & 0xff];
assert(entry.hasResource());
return entry;
}
PictureResource *BoltFile::getPictureResource(uint32 id) {
if ((int32)id == -1)
return NULL;
if (id & 0xffff)
id <<= 16;
return getBoltEntryFromLong(id)._picResource;
}
CMapResource *BoltFile::getCMapResource(uint32 id) {
if ((int32)id == -1)
return NULL;
if (id & 0xffff)
id <<= 16;
return getBoltEntryFromLong(id)._cMapResource;
}
byte *BoltFile::memberAddr(uint32 id) {
BoltGroup &group = _groups[id >> 8];
if (!group._loaded)
return NULL;
// If an entry already has a processed representation, we shouldn't
// still be accessing the raw data
BoltEntry &entry = group._entries[id & 0xff];
assert(!entry.hasResource());
return entry._data;
}
byte *BoltFile::memberAddrOffset(uint32 id) {
BoltGroup &group = _groups[id >> 24];
if (!group._loaded)
return NULL;
// If an entry already has a processed representation, we shouldn't
// still be accessing the raw data
BoltEntry &entry = group._entries[(id >> 16) & 0xff];
assert(!entry.hasResource());
return entry._data + (id & 0xffff);
}
/**
* Resolves an Id to an offset within a loaded resource
*/
void BoltFile::resolveIt(uint32 id, byte **p) {
if ((int32)id == -1) {
*p = NULL;
} else {
byte *ptr = memberAddrOffset(id);
if (ptr) {
*p = ptr;
} else {
*p = NULL;
assert(_state._resolves.size() < 1000);
_state._resolves.push_back(ResolveEntry(id, p));
}
}
}
void BoltFile::resolveFunction(uint32 id, GraphicMethodPtr *fn) {
if ((int32)id == -1) {
*fn = NULL;
} else {
error("Function fnTermGro array not supported");
}
}
/**
* Resolve any data references to within resources that weren't
* previously loaded, but are now
*/
void BoltFile::resolveAll() {
for (uint idx = 0; idx < _state._resolves.size(); ++idx)
*_state._resolves[idx]._p = memberAddrOffset(_state._resolves[idx]._id);
}
byte *BoltFile::getBoltMember(uint32 id) {
_state._curLibPtr = this;
// Get the group, and load it's entry list if not already loaded
_state._curGroupPtr = &_groups[(id >> 8) & 0xff];
if (!_state._curGroupPtr->_loaded)
_state._curGroupPtr->load();
// Get the entry
_state._curMemberPtr = &_state._curGroupPtr->_entries[id & 0xff];
if (_state._curMemberPtr->_field1)
initMem(_state._curMemberPtr->_field1);
// Return the data for the entry if it's already been loaded
if (_state._curMemberPtr->_data)
return _state._curMemberPtr->_data;
_state._xorMask = _state._curMemberPtr->_xorMask;
_state._encrypt = (_state._curMemberPtr->_mode & 0x10) != 0;
if (_state._curGroupPtr->_processed) {
// TODO: Figure out weird access type. Uncompressed read perhaps?
//int fileDiff = _state._curGroupPtr->_fileOffset - _state._curMemberPtr->_fileOffset;
error("TODO: processed bolt flag");
} else {
_state._bufStart = _state._decompressBuf;
_state._bufSize = DECOMPRESS_SIZE;
if ((_state._curFd != &_file) || (_state._curMemberPtr->_fileOffset < _state._bufferBegin)
|| (_state._curMemberPtr->_fileOffset >= _state._bufferEnd)) {
_state._bytesLeft = 0;
_state._bufPos = _state._bufStart;
_state._bufferBegin = -1;
_state._bufferEnd = _state._curMemberPtr->_fileOffset;
} else {
_state._bufPos = _state._curMemberPtr->_fileOffset - _state._bufferBegin + _state._bufStart;
_state._bytesLeft = _state._bufSize - (_state._bufPos - _state._bufStart);
}
}
_state._decompState = 0;
_state._historyIndex = 0;
// Initialise the resource
assert(_state._curMemberPtr->_initMethod < 25);
initResource(_state._curMemberPtr->_initMethod);
return _state._curMemberPtr->_data;
}
void BoltFile::initDefault() {
_state._curMemberPtr->_data = _state.decompress(0, _state._curMemberPtr->_size,
_state._curMemberPtr->_mode);
}
/*------------------------------------------------------------------------*/
BVoyBoltFile::BVoyBoltFile(BoltFilesState &state): BoltFile("bvoy.blt", state) {
}
void BVoyBoltFile::initResource(int resType) {
switch (resType) {
case 8:
sInitPic();
break;
case 10:
vInitCMap();
break;
case 11:
vInitCycl();
break;
case 15:
initViewPort();
break;
case 16:
initViewPortList();
break;
case 17:
initFont();
break;
case 18:
initFontInfo();
break;
case 19:
initSoundMap();
break;
default:
initDefault();
break;
}
}
void BVoyBoltFile::initViewPort() {
initDefault();
ViewPortResource *viewPort;
byte *src = _state._curMemberPtr->_data;
_state._curMemberPtr->_viewPortResource = viewPort = new ViewPortResource(_state, src);
// This is done post-constructor, since viewports can be self referential, so
// we ned the _viewPortResource field to have been set before resolving the pointer
viewPort->_parent = getBoltEntryFromLong(READ_LE_UINT32(src + 2))._viewPortResource;
}
void BVoyBoltFile::initViewPortList() {
initDefault();
ViewPortListResource *res;
_state._curMemberPtr->_viewPortListResource = res = new ViewPortListResource(
_state, _state._curMemberPtr->_data);
_state._vm->_graphicsManager._viewPortListPtr = res;
_state._vm->_graphicsManager._vPort = &res->_entries[0];
}
void BVoyBoltFile::initFontInfo() {
initDefault();
_state._curMemberPtr->_fontInfoResource = new FontInfoResource(
_state, _state._curMemberPtr->_data);
}
void BVoyBoltFile::initFont() {
initDefault();
_state._curMemberPtr->_fontResource = new FontResource(_state, _state._curMemberPtr->_data);
}
void BVoyBoltFile::initSoundMap() {
initDefault();
}
void BVoyBoltFile::sInitPic() {
// Read in the header data
_state._curMemberPtr->_data = _state.decompress(NULL, 24, _state._curMemberPtr->_mode);
_state._curMemberPtr->_picResource = new PictureResource(_state,
_state._curMemberPtr->_data);
}
void BVoyBoltFile::vInitCMap() {
initDefault();
_state._curMemberPtr->_cMapResource = new CMapResource(
_state, _state._curMemberPtr->_data);
}
void BVoyBoltFile::vInitCycl() {
initDefault();
_state._vm->_eventsManager.vStopCycle();
_state._curMemberPtr->_vInitCyclResource = new VInitCyclResource(
_state, _state._curMemberPtr->_data);
}
/*------------------------------------------------------------------------*/
StampBoltFile::StampBoltFile(BoltFilesState &state): BoltFile("stampblt.blt", state) {
}
void StampBoltFile::initResource(int resType) {
switch (resType) {
case 0:
initThread();
break;
case 6:
initPtr();
break;
case 24:
initControl();
break;
default:
initDefault();
break;
}
}
void StampBoltFile::initThread() {
initDefault();
_state._curMemberPtr->_threadResource = new ThreadResource(_state,
_state._curMemberPtr->_data);
}
void StampBoltFile::initPtr() {
initDefault();
_state._curMemberPtr->_ptrResource = new PtrResource(_state,
_state._curMemberPtr->_data);
}
void StampBoltFile::initControl() {
initDefault();
ControlResource *res;
_state._curMemberPtr->_controlResource = res = new ControlResource(_state,
_state._curMemberPtr->_data);
_state._vm->_controlGroupPtr = _state._curGroupPtr;
_state._vm->_controlPtr = res;
}
/*------------------------------------------------------------------------*/
BoltGroup::BoltGroup(Common::SeekableReadStream *f): _file(f) {
byte buffer[BOLT_GROUP_SIZE];
_loaded = false;
_file->read(&buffer[0], BOLT_GROUP_SIZE);
_processed = buffer[0] != 0;
_callInitGro = buffer[1] != 0;
_termGroIndex = buffer[2];
_count = buffer[3] ? buffer[3] : 256; // TODO: Added this in. Check it's okay
_fileOffset = READ_LE_UINT32(&buffer[8]);
}
BoltGroup::~BoltGroup() {
}
void BoltGroup::load() {
_file->seek(_fileOffset);
// Read the entries
for (int i = 0; i < _count; ++i)
_entries.push_back(BoltEntry(_file));
_loaded = true;
}
void BoltGroup::unload() {
if (!_loaded)
return;
_entries.clear();
_loaded = false;
}
/*------------------------------------------------------------------------*/
BoltEntry::BoltEntry(Common::SeekableReadStream *f): _file(f) {
_data = NULL;
_picResource = NULL;
_viewPortResource = NULL;
_viewPortListResource = NULL;
_fontResource = NULL;
_fontInfoResource = NULL;
_cMapResource = NULL;
_vInitCyclResource = NULL;
_ptrResource = NULL;
_controlResource = NULL;
_threadResource = NULL;
byte buffer[16];
_file->read(&buffer[0], 16);
_mode = buffer[0];
_field1 = buffer[1];
_initMethod = buffer[3];
_xorMask = buffer[4] & 0xff; // TODO: Is this right??
_size = READ_LE_UINT32(&buffer[4]);
_fileOffset = READ_LE_UINT32(&buffer[8]);
}
BoltEntry::~BoltEntry() {
delete[] _data;
delete _picResource;
delete _viewPortResource;
delete _viewPortListResource;
delete _fontResource;
delete _fontInfoResource;
delete _cMapResource;
delete _vInitCyclResource;
delete _ptrResource;
delete _controlResource;
}
void BoltEntry::load() {
// TODO: Currently, all entry loading and decompression is done in BoltFile::memberAddr.
// Ideally, a lot of the code should be moved here
}
/**
* Returns true if the given bolt entry has an attached resource
*/
bool BoltEntry::hasResource() const {
return _picResource || _viewPortResource || _viewPortListResource
|| _fontResource || _fontInfoResource || _cMapResource
|| _vInitCyclResource || _ptrResource || _controlResource
|| _threadResource;
}
/*------------------------------------------------------------------------*/
PictureResource::PictureResource(BoltFilesState &state, const byte *src) {
_flags = READ_LE_UINT16(src);
_select = src[2];
_pick = src[3];
_onOff = src[4];
_depth = src[5];
int xs = READ_LE_UINT16(&src[6]);
int ys = READ_LE_UINT16(&src[8]);
_bounds = Common::Rect(xs, ys, xs + READ_LE_UINT16(&src[10]),
ys + READ_LE_UINT16(&src[12]));
_maskData = READ_LE_UINT32(&src[14]);
_planeSize = READ_LE_UINT16(&src[22]);
_imgData = NULL;
int nbytes = _bounds.width() * _bounds.height();
if (_flags & 0x20) {
error("TODO: sInitPic flags&0x20");
} else if (_flags & 8) {
int mode = 0;
if (_bounds.width() == 320) {
mode = 147;
state._sImageShift = 2;
state._SVGAReset = false;
} else {
state._SVGAReset = true;
if (_bounds.width() == 640) {
if (_bounds.height() == 400) {
mode = 220;
state._sImageShift = 3;
} else {
mode = 221;
state._sImageShift = 3;
}
} else if (_bounds.width() == 800) {
mode = 222;
state._sImageShift = 3;
} else if (_bounds.width() == 1024) {
mode = 226;
state._sImageShift = 3;
}
}
if (mode != state._vm->_graphicsManager._SVGAMode) {
state._vm->_graphicsManager._SVGAMode = mode;
state._vm->_graphicsManager.clearPalette();
}
// byte *imgData = _imgData;
if (_flags & 0x10) {
// TODO: Figure out what it's doing. Looks like a direct clearing
// of the screen directly
} else {
// TODO: Figure out direct screen loading
}
} else {
if (_flags & 0x1000) {
if (!(_flags & 0x10))
nbytes = state._curMemberPtr->_size - 24;
int mask = (nbytes + 0x3FFF) >> 14;
_imgData = NULL;
if (state._boltPageFrame == 0)
state.EMSGetFrameAddr(&state._boltPageFrame);
if (state._boltPageFrame != 0) {
if (!state.EMSAllocatePages(&_planeSize)) {
_maskData = mask;
for (int idx = 0; idx < mask; ++idx)
state.EMSMapPageHandle(_planeSize, idx, idx);
state.decompress(state._boltPageFrame, nbytes, state._curMemberPtr->_mode);
return;
}
}
}
if (_flags & 0x10) {
_imgData = new byte[nbytes];
Common::fill(_imgData, _imgData + nbytes, 0);
} else {
_imgData = state.decompress(NULL, nbytes, state._curMemberPtr->_mode);
}
}
}
PictureResource::PictureResource() {
_flags = 0;
_select = 0;
_pick = 0;
_onOff = 0;
_depth = 0;
_maskData = 0;
_planeSize = 0;
_imgData = NULL;
}
PictureResource::PictureResource(int flags, int select, int pick, int onOff,
int depth, const Common::Rect &bounds, int maskData, byte *imgData,
int planeSize) {
_flags = flags;
_select = select;
_pick = pick;
_onOff = onOff;
_depth = depth;
_bounds = bounds;
_maskData = maskData;
_imgData = imgData;
_planeSize = planeSize;
}
PictureResource::~PictureResource() {
delete[] _imgData;
}
/*------------------------------------------------------------------------*/
ViewPortResource::ViewPortResource(BoltFilesState &state, const byte *src):
_fontChar(0, 0xff, 0xff, 0, 0, Common::Rect(), 0, NULL, 0), _state(state) {
_flags = READ_LE_UINT16(src);
_parent = NULL;
_pageCount = READ_LE_UINT16(src + 6);
_pageIndex = READ_LE_UINT16(src + 8);
_lastPage = READ_LE_UINT16(src + 10);
int xs = READ_LE_UINT16(src + 12);
int ys = READ_LE_UINT16(src + 14);
_bounds = Common::Rect(xs, ys, xs + READ_LE_UINT16(src + 16),
ys + READ_LE_UINT16(src + 18));
_field18 = READ_LE_UINT16(src + 0x18);
_currentPic = state._curLibPtr->getPictureResource(READ_LE_UINT32(src + 0x20));
_activePage = state._curLibPtr->getPictureResource(READ_LE_UINT32(src + 0x24));
_pages[0] = state._curLibPtr->getPictureResource(READ_LE_UINT32(src + 0x28));
_pages[1] = state._curLibPtr->getPictureResource(READ_LE_UINT32(src + 0x2C));
state._curLibPtr->resolveIt(READ_LE_UINT32(src + 0x30), &_field30);
// Get the rect list
for (int listIndex = 0; listIndex < 3; ++listIndex) {
_rectListCount[listIndex] = (int16)READ_LE_UINT16(src + 0x40 + 2 * listIndex);
uint32 id = READ_LE_UINT32(src + 0x34 + listIndex * 4);
if (id == -1) {
_rectListPtr[listIndex] = NULL;
} else {
_rectListPtr[listIndex] = new Common::Array<Common::Rect>();
if (_rectListCount[listIndex] > 0) {
int16 *rectList = (int16 *)state._curLibPtr->memberAddrOffset(id);
for (int i = 0; i < _rectListCount[listIndex]; ++i) {
int xs = FROM_LE_16(rectList[0]);
int ys = FROM_LE_16(rectList[1]);
_rectListPtr[i]->push_back(Common::Rect(xs, ys, xs + FROM_LE_16(rectList[2]),
ys + FROM_LE_16(rectList[3])));
}
}
}
}
xs = READ_LE_UINT16(src + 0x46);
ys = READ_LE_UINT16(src + 0x48);
_clipRect = Common::Rect(xs, ys, xs + READ_LE_UINT16(src + 0x4A),
ys + READ_LE_UINT16(src + 0x4C));
state._curLibPtr->resolveIt(READ_LE_UINT32(src + 0x7A), &_field7A);
state._curLibPtr->resolveFunction(READ_LE_UINT32(src + 0x7E), (GraphicMethodPtr *)&_fn1);
state._curLibPtr->resolveFunction(READ_LE_UINT32(src + 0x82), (GraphicMethodPtr *)&_setupFn);
state._curLibPtr->resolveFunction(READ_LE_UINT32(src + 0x86), (GraphicMethodPtr *)&_addFn);
state._curLibPtr->resolveFunction(READ_LE_UINT32(src + 0x8A), (GraphicMethodPtr *)&_restoreFn);
if (!_restoreFn && _addFn)
_addFn = &GraphicsManager::addRectNoSaveBack;
}
ViewPortResource::~ViewPortResource() {
for (int i = 0; i < 3; ++i)
delete _rectListPtr[i];
}
void ViewPortResource::setupViewPort(PictureResource *page, Common::Rect *clipRect,
ViewPortSetupPtr setupFn, ViewPortAddPtr addFn, ViewPortRestorePtr restoreFn) {
PictureResource *pic = _currentPic;
Common::Rect r = _bounds;
r.translate(pic->_bounds.left, pic->_bounds.top);
int xDiff, yDiff;
if (page) {
// Clip based on the passed picture resource
xDiff = page->_bounds.left - r.left;
yDiff = page->_bounds.top - r.top;
if (xDiff > 0) {
int width = r.width();
r.left = page->_bounds.left;
r.setWidth(xDiff <= width ? width - xDiff : 0);
}
if (yDiff > 0) {
int height = r.height();
r.top = page->_bounds.top;
r.setHeight(yDiff <= height ? height - yDiff : 0);
}
xDiff = r.right - page->_bounds.right;
yDiff = r.bottom - page->_bounds.bottom;
if (xDiff > 0)
r.setWidth(xDiff <= r.width() ? r.width() - xDiff : 0);
if (yDiff > 0)
r.setHeight(yDiff <= r.height() ? r.height() - yDiff : 0);
}
if (clipRect) {
// Clip based on the passed clip rectangles
xDiff = clipRect->left - r.left;
yDiff = clipRect->top - r.top;
if (xDiff > 0) {
int width = r.width();
r.left = clipRect->left;
r.setWidth(xDiff <= width ? width - xDiff : 0);
}
if (yDiff > 0) {
int height = r.height();
r.top = clipRect->top;
r.setHeight(yDiff <= height ? height - yDiff : 0);
}
xDiff = r.right - clipRect->right;
yDiff = r.right - clipRect->right;
if (xDiff > 0)
r.setWidth(xDiff <= r.width() ? r.width() - xDiff : 0);
if (yDiff > 0)
r.setHeight(yDiff <= r.height() ? r.height() - yDiff : 0);
}
// clip = (0x20, 0x14, width: 0x140, height: 0C8h
_activePage = page;
_field18 = 0;
_clipRect = r;
_setupFn = setupFn;
_addFn = addFn;
_restoreFn = restoreFn;
if (setupFn)
(_state._vm->_graphicsManager.*setupFn)(this);
}
void ViewPortResource::setupViewPort() {
setupViewPort(_state._vm->_graphicsManager._backgroundPage, NULL,
&GraphicsManager::setupMCGASaveRect, &GraphicsManager::addRectOptSaveRect,
&GraphicsManager::restoreMCGASaveRect);
}
int ViewPortResource::drawText(const Common::String &msg) {
GraphicsManager &gfxManager = _state._vm->_graphicsManager;
assert(gfxManager._fontPtr);
assert(gfxManager._fontPtr->_curFont);
FontInfoResource &fontInfo = *gfxManager._fontPtr;
FontResource &fontData = *fontInfo._curFont;
int xShadows[9] = { 0, 1, 1, 1, 0, -1, -1, -1, 0 };
int yShadows[9] = { 0, 1, 0, -1, -1, -1, 0, 1, 1 };
Common::Rect *clipPtr = gfxManager._clipPtr;
if (!(fontInfo._picFlags & DISPFLAG_1))
gfxManager._clipPtr = NULL;
int minChar = fontData._minChar;
int padding = fontData._padding;
int fontHeight = fontData._fontHeight;
int totalChars = fontData._maxChar - fontData._minChar;
int msgWidth = 0;
int xp = 0, yp = 0;
Common::Point pos = Common::Point(fontInfo._pos.x, fontInfo._pos.y + fontData._topPadding);
_fontChar._flags = fontInfo._picFlags | DISPFLAG_2;
_fontChar._select = fontInfo._picSelect;
_fontChar._bounds.setHeight(fontHeight);
if (gfxManager._drawTextPermFlag || (fontInfo._fontFlags & DISPFLAG_1) || fontInfo._justify ||
(gfxManager._saveBack && fontInfo._fontSaveBack && (_flags & DISPFLAG_VIEWPORT))) {
msgWidth = textWidth(msg);
yp = pos.y;
xp = pos.x;
switch (fontInfo._justify) {
case 1:
xp = pos.x + (fontInfo._justifyWidth / 2) - (msgWidth / 2);
break;
case 2:
xp = pos.x + fontInfo._justifyWidth - msgWidth;
break;
default:
break;
}
if (!(fontInfo._fontFlags & 3)) {
_fontRect.left = xp;
_fontRect.top = yp;
_fontRect.setWidth(msgWidth);
_fontRect.setHeight(fontHeight);
} else {
_fontRect.left = pos.x;
_fontRect.top = pos.y;
_fontRect.setWidth(fontInfo._justifyWidth);
_fontRect.setHeight(fontInfo._justifyHeight);
}
pos.x = xp;
pos.y = yp;
if (fontInfo._fontFlags & 4) {
if (fontInfo._shadow.x <= 0) {
_fontRect.left += fontInfo._shadow.x;
_fontRect.right -= fontInfo._shadow.x * 2;
} else {
_fontRect.right += fontInfo._shadow.x;
}
if (fontInfo._shadow.y <= 0) {
_fontRect.top += fontInfo._shadow.y;
_fontRect.bottom -= fontInfo._shadow.y * 2;
} else {
_fontRect.bottom += fontInfo._shadow.y;
}
} else if (fontInfo._fontFlags & 8) {
if (fontInfo._shadow.x <= 0) {
_fontRect.left += fontInfo._shadow.x;
_fontRect.right -= fontInfo._shadow.x * 3;
} else {
_fontRect.right += fontInfo._shadow.x * 3;
_fontRect.left -= fontInfo._shadow.x;
}
if (fontInfo._shadow.y <= 0) {
_fontRect.top += fontInfo._shadow.y;
_fontRect.bottom -= fontInfo._shadow.y * 3;
} else {
_fontRect.bottom += fontInfo._shadow.y * 3;
_fontRect.top -= fontInfo._shadow.y;
}
}
}
if (gfxManager._saveBack && fontInfo._fontSaveBack && (_flags & DISPFLAG_VIEWPORT)) {
addSaveRect(_pageIndex, _fontRect);
}
if (fontInfo._fontFlags & DISPFLAG_1) {
gfxManager._drawPtr->_pos = Common::Point(_fontRect.left, _fontRect.top);
gfxManager._drawPtr->_penColor = fontInfo._backColor;
sFillBox(_fontRect.width());
}
bool saveBack = gfxManager._saveBack;
gfxManager._saveBack = false;
int count = 0;
if (fontInfo._fontFlags & DISPFLAG_4)
count = 1;
else if (fontInfo._fontFlags & DISPFLAG_8)
count = 8;
for (int i = count; i >= 0; --i) {
xp = pos.x;
yp = pos.y;
switch (xShadows[i]) {
case -1:
xp -= fontInfo._shadow.x;
break;
case 1:
xp += fontInfo._shadow.x;
break;
default:
break;
}
switch (yShadows[i]) {
case -1:
yp -= fontInfo._shadow.y;
break;
case 1:
yp += fontInfo._shadow.y;
break;
default:
break;
}
if (i != 0) {
_fontChar._pick = 0;
_fontChar._onOff = fontInfo._shadowColor;
} else if (fontData.field2 == 1 || (fontInfo._fontFlags & 0x10)) {
_fontChar._pick = 0;
_fontChar._onOff = fontInfo._foreColor;
} else {
_fontChar._pick = fontInfo._picPick;
_fontChar._onOff = fontInfo._picOnOff;
_fontChar._depth = fontData.field2;
}
// Loop to draw each character in turn
msgWidth = -padding;
const char *msgP = msg.c_str();
char ch;
while ((ch = *msgP++) != '\0') {
int charValue = (int)ch - minChar;
if (charValue < 0 || charValue >= totalChars || fontData._charWidth[charValue] == 0)
charValue = fontData._maxChar - minChar;
int charWidth = fontData._charWidth[charValue];
_fontChar._bounds.setWidth(charWidth);
uint16 offset = READ_LE_UINT16(fontData._charOffsets + charValue * 2);
_fontChar._imgData = fontData._charImages + offset * 2;
gfxManager.sDrawPic(&_fontChar, this, Common::Point(xp, yp));
_fontChar._imgData = NULL;
xp += charWidth + padding;
msgWidth += charWidth + padding;
}
}
msgWidth = MAX(msgWidth, 0);
if (fontInfo._justify == ALIGN_LEFT)
fontInfo._pos.x = xp;
gfxManager._saveBack = saveBack;
gfxManager._clipPtr = clipPtr;
return msgWidth;
}
int ViewPortResource::textWidth(const Common::String &msg) {
if (msg.size() == 0)
return 0;
const char *msgP = msg.c_str();
FontResource &fontData = *_state._vm->_graphicsManager._fontPtr->_curFont;
int minChar = fontData._minChar;
int maxChar = fontData._maxChar;
int padding = fontData._padding;
int totalWidth = -padding;
char ch;
// Loop through the characters
while ((ch = *msgP++) != '\0') {
int charValue = (int)ch;
if (charValue < minChar || charValue > maxChar)
charValue = maxChar;
if (!fontData._charWidth[charValue - minChar])
charValue = maxChar;
totalWidth += fontData._charWidth[charValue - minChar] + padding;
}
if (totalWidth < 0)
totalWidth = 0;
return totalWidth;
}
void ViewPortResource::addSaveRect(int pageIndex, const Common::Rect &r) {
// TODO
}
void ViewPortResource::sFillBox(int width) {
// TODO
}
void ViewPortResource::fillPic(byte onOff) {
_state._vm->_graphicsManager.fillPic(this, onOff);
}
/*------------------------------------------------------------------------*/
ViewPortListResource::ViewPortListResource(BoltFilesState &state, const byte *src) {
uint count = READ_LE_UINT16(src);
_palIndex = READ_LE_UINT16(src + 2);
// Load palette map
byte *palData = state._curLibPtr->memberAddr(READ_LE_UINT32(src + 4));
for (uint i = 0; i < 256; ++i, palData += 16)
_palette.push_back(ViewPortPalEntry(palData));
// Load view port pointer list
uint32 *idP = (uint32 *)&src[8];
for (uint i = 0; i < count; ++i, ++idP) {
uint32 id = READ_LE_UINT32(idP);
BoltEntry &entry = state._curLibPtr->getBoltEntryFromLong(id);
assert(entry._viewPortResource);
_entries.push_back(entry._viewPortResource);
}
}
/*------------------------------------------------------------------------*/
ViewPortPalEntry::ViewPortPalEntry(const byte *src) {
uint16 *v = (uint16 *)src;
_rEntry = READ_LE_UINT16(v++);
_gEntry = READ_LE_UINT16(v++);
_bEntry = READ_LE_UINT16(v++);
_rChange = READ_LE_UINT16(v++);
_gChange = READ_LE_UINT16(v++);
_bChange = READ_LE_UINT16(v++);
_palIndex = READ_LE_UINT16(v++);
}
/*------------------------------------------------------------------------*/
FontResource::FontResource(BoltFilesState &state, byte *src) {
_minChar = src[0];
_maxChar = src[1];
field2 = src[2];
_padding = src[3];
_fontHeight = src[5];
_topPadding = (int8)src[6];
int totalChars = _maxChar - _minChar + 1;
_charWidth = new int[totalChars];
for (int i = 0; i < totalChars; ++i)
_charWidth[i] = READ_LE_UINT16(src + 8 + 2 * i);
_charOffsets = src + 8 + totalChars * 2;
_charImages = _charOffsets + totalChars * 2;
}
FontResource::~FontResource() {
delete[] _charWidth;
}
/*------------------------------------------------------------------------*/
FontInfoResource::FontInfoResource(BoltFilesState &state, const byte *src) {
_curFont = NULL;
_picFlags = src[4];
_picSelect = src[5];
_picPick = src[6];
_picOnOff = src[7];
_fontFlags = src[8];
_justify = (FontJustify)src[9];
_fontSaveBack = READ_LE_UINT16(src + 10);
_pos.x = (int16)READ_LE_UINT16(src + 12);
_pos.y = (int16)READ_LE_UINT16(src + 14);
_justifyWidth = READ_LE_UINT16(src + 16);
_justifyHeight = READ_LE_UINT16(src + 18);
_shadow.x = READ_LE_UINT16(src + 20);
_shadow.y = READ_LE_UINT16(src + 22);
_foreColor = READ_LE_UINT16(src + 24);
_backColor = READ_LE_UINT16(src + 26);
_shadowColor = READ_LE_UINT16(src + 28);
}
FontInfoResource::FontInfoResource() {
_curFont = NULL;
_picFlags = 3;
_picSelect = 0xff;
_picPick = 0xff;
_picOnOff = 0;
_fontFlags = 0;
_justify = ALIGN_LEFT;
_fontSaveBack = 0;
_justifyWidth = 1;
_justifyHeight = 1;
_shadow = Common::Point(1, 1);
_foreColor = 1;
_backColor = 0;
_shadowColor = 0;
}
FontInfoResource::FontInfoResource(byte picFlags, byte picSelect, byte picPick, byte picOnOff,
byte fontFlags, FontJustify justify, int fontSaveBack, const Common::Point &pos,
int justifyWidth, int justifyHeight, const Common::Point &shadow, int foreColor,
int backColor, int shadowColor) {
_curFont = NULL;
_picFlags = picFlags;
_picSelect = picSelect;
_picPick = picPick;
_picOnOff = picOnOff;
_fontFlags = fontFlags;
_justify = justify;
_fontSaveBack = fontSaveBack;
_pos = pos;
_justifyWidth = justifyWidth;
_justifyHeight = justifyHeight;
_shadow = shadow;
_foreColor = foreColor;
_backColor = backColor;
_shadowColor = shadowColor;
}
/*------------------------------------------------------------------------*/
CMapResource::CMapResource(BoltFilesState &state, const byte *src): _vm(state._vm) {
_steps = src[0];
_fadeStatus = src[1];
_start = READ_LE_UINT16(src + 2);
_end = READ_LE_UINT16(src + 4);
int count = _end - _start + 1;
_entries = new byte[count * 3];
Common::copy(src + 6, src + 6 + 3 * count, _entries);
int palIndex = state._vm->_graphicsManager._viewPortListPtr->_palIndex;
if (_end > palIndex)
_end = palIndex;
if (_start > palIndex)
_start = palIndex;
}
CMapResource::~CMapResource() {
delete[] _entries;
}
void CMapResource::startFade() {
_vm->_eventsManager.startFade(this);
}
/*------------------------------------------------------------------------*/
VInitCyclResource::VInitCyclResource(BoltFilesState &state, const byte *src) {
for (int i = 0; i < 4; ++i) {
state._curLibPtr->resolveIt(READ_LE_UINT32(src + 8 + i * 4), &_ptr[i]);
}
}
/*------------------------------------------------------------------------*/
int ThreadResource::_stampFlags = 0;
int ThreadResource::_useCount[8];
byte *ThreadResource::_threadDataPtr = NULL;
ThreadResource::ThreadResource(BoltFilesState &state, const byte *src):
_vm(state._vm) {
_flags = src[8];
}
bool ThreadResource::loadAStack(int idx) {
if (_stampFlags & 1) {
unloadAStack(_controlIndex);
if (!_useCount[idx]) {
BoltEntry &boltEntry = _vm->_stampLibPtr->boltEntry(_vm->_controlPtr->_memberIds[idx]);
if (!boltEntry._data)
return false;
_vm->_controlPtr->_entries[idx] = boltEntry._data;
}
++_useCount[idx];
}
_ctlPtr = _vm->_controlPtr->_entries[idx];
return true;
}
void ThreadResource::unloadAStack(int idx) {
if ((_stampFlags & 1) && _useCount[idx]) {
if (--_useCount[idx] == 0) {
_vm->_stampLibPtr->freeBoltMember(_vm->_controlPtr->_memberIds[idx]);
}
}
}
bool ThreadResource::doState() {
_flags |= 1;
if (!getStateInfo())
return false;
warning("TODO: stm_doState");
return true;
}
bool ThreadResource::getStateInfo() {
_field9 = 0;
int id = READ_LE_UINT16(_ctlPtr);
if (id <= _threadId) {
_field9 |= 0x80;
return false;
} else {
uint32 fld = READ_LE_UINT32(_ctlPtr + 2);
fld += _threadId << 3;
_field46 = READ_LE_UINT32(_ctlPtr + fld + 4);
fld = READ_LE_UINT32(_ctlPtr + fld);
byte *baseP = _ctlPtr + fld;
_field42 = READ_LE_UINT16(baseP);
_field40 = READ_LE_UINT16(baseP + 2);
_field44 = READ_LE_UINT16(baseP + 4);
_field28E = getDataOffset();
_field28E += READ_LE_UINT32(baseP + 6) / 2;
_field4A = baseP + 10;
getButtonsText();
return true;
}
}
byte *ThreadResource::getDataOffset() {
uint32 offset = READ_LE_UINT32(_ctlPtr + 10);
_threadDataPtr = _ctlPtr + offset;
return _threadDataPtr;
}
void ThreadResource::getButtonsText() {
warning("TODO: stm_getButtonsText");
}
void ThreadResource::unloadAllStacks(VoyeurEngine *vm) {
if (_stampFlags & 1) {
for (int i = 0; i < 8; ++i) {
if (_useCount[i])
vm->_stampLibPtr->freeBoltMember(vm->_controlPtr->_memberIds[i]);
}
}
}
void ThreadResource::initUseCount() {
Common::fill(&_useCount[0], &_useCount[8], 0);
}
/*------------------------------------------------------------------------*/
PtrResource::PtrResource(BoltFilesState &state, const byte *src) {
// Load pointer list
uint32 *idP = (uint32 *)&src[0];
int size = state._curMemberPtr->_size;
for (int i = 0; i < size / 4; ++i, ++idP) {
uint32 id = READ_LE_UINT32(idP);
BoltEntry &entry = state._curLibPtr->getBoltEntryFromLong(id);
_entries.push_back(&entry);
}
}
/*------------------------------------------------------------------------*/
ControlResource::ControlResource(BoltFilesState &state, const byte *src) {
// Get pointer
uint32 ptrId = READ_LE_UINT32(&src[0x32]);
_ptr = state._curLibPtr->getBoltEntryFromLong(ptrId)._data;
for (int i = 0; i < 8; ++i)
_memberIds[i] = READ_LE_UINT16(src + i * 2);
// Load pointer list
uint32 *idP = (uint32 *)&src[0x10];
int count = READ_LE_UINT16(&src[0x36]);
for (int i = 0; i < count; ++i, ++idP) {
uint32 id = READ_LE_UINT32(idP);
state._curLibPtr->resolveIt(id, &_entries[i]);
}
}
} // End of namespace Voyeur
|