diff options
Diffstat (limited to 'engines/sci')
-rw-r--r-- | engines/sci/engine/game.cpp | 5 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/scriptdebug.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/state.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/state.h | 2 | ||||
-rw-r--r-- | engines/sci/vocab_debug.cpp | 35 | ||||
-rw-r--r-- | engines/sci/vocabulary.h | 11 |
7 files changed, 18 insertions, 41 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 6fefa6ab96..eff320edfc 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -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) { diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 0e9fa28457..bca5df65b5 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -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)); diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 3407fc5b08..e7345b93b7 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -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]) { diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp index 03cd1dbbdf..e57230387d 100644 --- a/engines/sci/engine/state.cpp +++ b/engines/sci/engine/state.cpp @@ -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; diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h index 476b2f9f00..e7755d3388 100644 --- a/engines/sci/engine/state.h +++ b/engines/sci/engine/state.h @@ -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 */ diff --git a/engines/sci/vocab_debug.cpp b/engines/sci/vocab_debug.cpp index aecbdd9814..5578c24487 100644 --- a/engines/sci/vocab_debug.cpp +++ b/engines/sci/vocab_debug.cpp @@ -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"); - } - 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); + o[i].name = "undefined"; } - free(opcodes); } // Alternative kernel func names retriever. Required for KQ1/SCI (at least). diff --git a/engines/sci/vocabulary.h b/engines/sci/vocabulary.h index 0ca8613844..b8dcee795c 100644 --- a/engines/sci/vocabulary.h +++ b/engines/sci/vocabulary.h @@ -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. |