SCI: Changed EngineState::opcodes to a Common::Array (maybe we shold just remove the relevant code completely, though, it seems useless, esp. as long as we hardcode the way we interpret every opcode

svn-id: r40740
This commit is contained in:
Max Horn 2009-05-20 17:52:33 +00:00
parent 7d54385dea
commit 4c786a44c9
7 changed files with 18 additions and 41 deletions

View file

@ -53,7 +53,7 @@ static int _init_vocabulary(EngineState *s) { // initialize vocabulary and relat
s->parser_rules = NULL;
}
s->opcodes = vocabulary_get_opcodes(s->resmgr);
vocabulary_get_opcodes(s->resmgr, s->_opcodes);
if (!vocabulary_get_snames(s->resmgr, (s->flags & GF_SCI0_OLD), s->_selectorNames)) {
sciprintf("_init_vocabulary(): Could not retrieve selector names (vocab.997)!\n");
@ -500,8 +500,7 @@ void script_free_engine(EngineState *s) {
s->_selectorNames.clear();
s->_kernelNames.clear();
vocabulary_free_opcodes(s->opcodes);
s->opcodes = NULL;
s->_opcodes.clear();
}
void script_free_breakpoints(EngineState *s) {

View file

@ -834,7 +834,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
retval->_selectorNames = s->_selectorNames;
retval->_kernelNames = s->_kernelNames;
retval->_kfuncTable = s->_kfuncTable;
retval->opcodes = s->opcodes;
retval->_opcodes = s->_opcodes;
memcpy(&(retval->selector_map), &(s->selector_map), sizeof(selector_map_t));

View file

@ -1302,7 +1302,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
if (print_bw_tag)
sciprintf("[%c] ", opsize ? 'B' : 'W');
sciprintf("%s", s->opcodes[opcode].name);
sciprintf("%s", s->_opcodes[opcode].name.c_str());
i = 0;
while (g_opcode_formats[opcode][i]) {

View file

@ -136,8 +136,6 @@ EngineState::EngineState() : _dirseeker(this) {
seg_manager = 0;
gc_countdown = 0;
opcodes = 0;
memset(&selector_map, 0, sizeof(selector_map)); // FIXME: Remove this once/if we C++ify selector_map_t
successor = 0;

View file

@ -263,7 +263,7 @@ public:
Common::Array<kfunct_sig_pair_t> _kfuncTable; /**< Table of kernel functions */
opcode *opcodes;
Common::Array<opcode> _opcodes;
selector_map_t selector_map; /**< Shortcut list for important selectors */

View file

@ -354,51 +354,36 @@ int vocabulary_lookup_sname(const Common::StringList &selectorNames, const char
return -1;
}
opcode* vocabulary_get_opcodes(ResourceManager *resmgr) {
opcode* o;
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) {
fprintf(stderr, "unable to load vocab.%03d\n", VOCAB_RESOURCE_OPCODES);
return NULL;
warning("unable to load vocab.%03d", VOCAB_RESOURCE_OPCODES);
return;
}
count = READ_LE_UINT16(r->data);
o = (opcode*)malloc(sizeof(opcode) * 256);
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 = (char *)malloc(len + 1);
memcpy(o[i].name, r->data + offset + 4, len);
o[i].name[len] = '\0';
#ifdef VOCABULARY_DEBUG
printf("Opcode %02X: %s, %d\n", i, o[i].name, o[i].type);
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 = (char *)malloc(strlen("undefined") + 1);
strcpy(o[i].name, "undefined");
o[i].name = "undefined";
}
return o;
}
void vocabulary_free_opcodes(opcode *opcodes) {
int i;
if (!opcodes)
return;
for (i = 0; i < 256; i++) {
if (opcodes[i].name)
free(opcodes[i].name);
}
free(opcodes);
}
// Alternative kernel func names retriever. Required for KQ1/SCI (at least).

View file

@ -49,7 +49,7 @@ class ResourceManager;
struct opcode {
int type;
int number;
char* name;
Common::String name;
};
#define VOCAB_RESOURCE_OPCODES 998
@ -199,14 +199,9 @@ int vocabulary_lookup_sname(const Common::StringList &selectorNames, const char
/**
* Returns a null terminated array of opcodes.
* Obtain the list of opcodes.
*/
opcode *vocabulary_get_opcodes(ResourceManager *resmgr);
void vocabulary_free_opcodes(opcode *opcodes);
/* Frees a previously allocated list of opcodes
** Parameters: (opcode *) opcodes: Opcodes to free
*/
void vocabulary_get_opcodes(ResourceManager *resmgr, Common::Array<opcode> &opcodes);
/**
* Fills a StringList with kernel function names.