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
|
/* 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 "sci/sci.h"
#include "sci/engine/state.h"
#include "sci/resource.h"
namespace Sci {
#if 0
int *vocabulary_get_classes(ResourceManager *resmgr, int* count) {
Resource* r;
int *c;
unsigned int i;
if ((r = resmgr->findResource(kResourceTypeVocab, 996, 0)) == NULL)
return 0;
c = (int *)malloc(sizeof(int) * r->size / 2);
for (i = 2; i < r->size; i += 4) {
c[i/4] = READ_LE_UINT16(r->data + i);
}
*count = r->size / 4;
return c;
}
int vocabulary_get_class_count(ResourceManager *resmgr) {
Resource* r;
if ((r = resmgr->findResource(kResourceTypeVocab, 996, 0)) == 0)
return 0;
return r->size / 4;
}
#endif
bool vocabulary_get_snames(ResourceManager *resmgr, bool isOldSci0, Common::StringList &selectorNames) {
int count;
Resource *r = resmgr->findResource(kResourceTypeVocab, 997, 0);
if (!r) // No such resource?
return false;
count = READ_LE_UINT16(r->data) + 1; // Counter is slightly off
for (int i = 0; i < count; i++) {
int offset = READ_LE_UINT16(r->data + 2 + i * 2);
int len = READ_LE_UINT16(r->data + offset);
Common::String tmp((const char *)r->data + offset + 2, len);
selectorNames.push_back(tmp);
// Early SCI versions used the LSB in the selector ID as a read/write
// toggle. To compensate for that, we add every selector name twice.
if (isOldSci0)
selectorNames.push_back(tmp);
}
return true;
}
void vocabulary_get_opcodes(ResourceManager *resmgr, Common::Array<opcode> &o) {
int count, i = 0;
Resource* r = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_OPCODES, 0);
o.clear();
// if the resource couldn't be loaded, leave
if (r == NULL) {
warning("unable to load vocab.%03d", VOCAB_RESOURCE_OPCODES);
return;
}
count = READ_LE_UINT16(r->data);
o.resize(256);
for (i = 0; i < count; i++) {
int offset = READ_LE_UINT16(r->data + 2 + i * 2);
int len = READ_LE_UINT16(r->data + offset) - 2;
o[i].type = READ_LE_UINT16(r->data + offset + 2);
o[i].number = i;
o[i].name = Common::String((char *)r->data + offset + 4, len);
#if 1 //def VOCABULARY_DEBUG
printf("Opcode %02X: %s, %d\n", i, o[i].name.c_str(), o[i].type);
#endif
}
for (i = count; i < 256; i++) {
o[i].type = 0;
o[i].number = i;
o[i].name = "undefined";
}
}
} // End of namespace Sci
|