SCI: Merged vocab_debug.cpp into vocabulary.cpp; cleanup

svn-id: r40915
This commit is contained in:
Max Horn 2009-05-26 14:44:14 +00:00
parent 1e2c539e42
commit c96cf97ea7
7 changed files with 150 additions and 184 deletions

View file

@ -119,7 +119,7 @@ bool Console::cmdGetVersion(int argc, const char **argv) {
bool Console::cmdSelectors(int argc, const char **argv) {
Common::StringList selectorNames;
if (!vocabulary_get_snames(_vm->getResMgr(), (_vm->getFlags() & GF_SCI0_OLD), selectorNames)) {
if (!vocab_get_snames(_vm->getResMgr(), (_vm->getFlags() & GF_SCI0_OLD), selectorNames)) {
DebugPrintf("No selector name table found!\n");
return true;
}
@ -139,7 +139,7 @@ bool Console::cmdSelectors(int argc, const char **argv) {
bool Console::cmdKernelNames(int argc, const char **argv) {
Common::StringList kernelNames;
vocabulary_get_knames(_vm->getResMgr(), kernelNames);
vocab_get_knames(_vm->getResMgr(), kernelNames);
if (kernelNames.empty()) {
DebugPrintf("No kernel name table found!\n");
@ -290,7 +290,7 @@ bool Console::cmdDissectScript(int argc, const char **argv) {
return true;
}
if (!vocabulary_get_snames(_vm->getResMgr(), (_vm->getFlags() & GF_SCI0_OLD), selectorNames)) {
if (!vocab_get_snames(_vm->getResMgr(), (_vm->getFlags() & GF_SCI0_OLD), selectorNames)) {
DebugPrintf("No selector name table found!\n");
return true;
}

View file

@ -41,7 +41,7 @@ static int _init_vocabulary(EngineState *s) { // initialize vocabulary and relat
s->parser_lastmatch_word = SAID_NO_MATCH;
s->parser_rules = NULL;
sciprintf("Initializing vocabulary\n");
debug(2, "Initializing vocabulary");
if (s->resmgr->_sciVersion < SCI_VERSION_01_VGA && vocab_get_words(s->resmgr, s->_parserWords)) {
vocab_get_suffixes(s->resmgr, s->_parserSuffixes);
@ -49,14 +49,14 @@ static int _init_vocabulary(EngineState *s) { // initialize vocabulary and relat
// Now build a GNF grammar out of this
s->parser_rules = vocab_build_gnf(s->_parserBranches);
} else {
sciprintf("Assuming that this game does not use a parser.\n");
debug(2, "Assuming that this game does not use a parser.");
s->parser_rules = NULL;
}
vocabulary_get_opcodes(s->resmgr, s->_opcodes);
vocab_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");
if (!vocab_get_snames(s->resmgr, (s->flags & GF_SCI0_OLD), s->_selectorNames)) {
warning("_init_vocabulary(): Could not retrieve selector names");
return 1;
}
@ -70,7 +70,7 @@ int _reset_graphics_input(EngineState *s) {
Resource *resource;
int font_nr;
gfx_color_t transparent = { PaletteEntry(), 0, -1, -1, 0 };
sciprintf("Initializing graphics\n");
debug(2, "Initializing graphics");
if (s->resmgr->_sciVersion <= SCI_VERSION_01 || (s->flags & GF_SCI1_EGA)) {
int i;
@ -101,7 +101,7 @@ int _reset_graphics_input(EngineState *s) {
s->gfx_state->gfxResMan->setStaticPalette(gfxr_read_pal11(999, resource->data, resource->size));
s->resmgr->unlockResource(resource, 999, kResourceTypePalette);
} else {
sciprintf("Couldn't find the default palette!\n");
debug(2, "Couldn't find the default palette!");
}
}
}
@ -135,7 +135,7 @@ int _reset_graphics_input(EngineState *s) {
} while ((!resource) && (font_nr < sci_max_resource_nr[s->resmgr->_sciVersion]));
if (!resource) {
sciprintf("No text font was found.\n");
debug(2, "No text font was found.");
return 1;
}
@ -203,7 +203,7 @@ int game_init_graphics(EngineState *s) {
}
static void _free_graphics_input(EngineState *s) {
sciprintf("Freeing graphics\n");
debug(2, "Freeing graphics");
delete s->visual;
@ -280,7 +280,7 @@ int create_class_table_sci11(EngineState *s) {
classnr = READ_LE_UINT16((byte*)seeker_ptr + 10);
if (classnr >= (int)s->_classtable.size()) {
if (classnr >= SCRIPT_MAX_CLASSTABLE_SIZE) {
warning("Invalid class number 0x%x in script.%d(0x%x), offset %04x\n",
warning("Invalid class number 0x%x in script.%d(0x%x), offset %04x",
classnr, scriptnr, scriptnr, seeker_offset);
return 1;
}
@ -347,7 +347,7 @@ static int create_class_table_sci0(EngineState *s) {
if (classnr >= (int)s->_classtable.size()) {
if (classnr >= SCRIPT_MAX_CLASSTABLE_SIZE) {
warning("Invalid class number 0x%x in script.%d(0x%x), offset %04x\n",
warning("Invalid class number 0x%x in script.%d(0x%x), offset %04x",
classnr, scriptnr, scriptnr, seeker);
return 1;
}
@ -391,18 +391,18 @@ int script_init_engine(EngineState *s, sci_version_t version) {
else
result = create_class_table_sci0(s);
s->seg_manager = new SegManager(s->version >= SCI_VERSION_1_1);
s->gc_countdown = GC_INTERVAL - 1;
if (result) {
sciprintf("Failed to initialize class table\n");
debug(2, "Failed to initialize class table");
return 1;
}
s->seg_manager = new SegManager(s->version >= SCI_VERSION_1_1);
s->gc_countdown = GC_INTERVAL - 1;
SegmentId script_000_segment = script_get_segment(s, 0, SCRIPT_GET_LOCK);
if (script_000_segment <= 0) {
sciprintf("Failed to instantiate script.000\n");
debug(2, "Failed to instantiate script.000");
return 1;
}
@ -426,7 +426,7 @@ int script_init_engine(EngineState *s, sci_version_t version) {
s->_executionStack.clear(); // Start without any execution stack
s->execution_stack_base = -1; // No vm is running yet
vocabulary_get_knames(s->resmgr, s->_kernelNames);
vocab_get_knames(s->resmgr, s->_kernelNames);
script_map_kernel(s);
// Maps the kernel functions
@ -443,7 +443,7 @@ int script_init_engine(EngineState *s, sci_version_t version) {
else
s->seg_manager->setExportWidth(0);
sciprintf("Engine initialized\n");
debug(2, "Engine initialized");
s->pic_priority_table = NULL;
s->_pics.clear();
@ -471,7 +471,7 @@ void script_set_gamestate_save_dir(EngineState *s, reg_t path) {
#endif
void script_free_vm_memory(EngineState *s) {
sciprintf("Freeing VM memory\n");
debug(2, "Freeing VM memory");
s->_classtable.clear();
@ -483,7 +483,7 @@ void script_free_vm_memory(EngineState *s) {
void script_free_engine(EngineState *s) {
script_free_vm_memory(s);
sciprintf("Freeing state-dependant data\n");
debug(2, "Freeing state-dependant data");
s->_kfuncTable.clear();
@ -527,7 +527,7 @@ int game_init(EngineState *s) {
s->stack_top = s->stack_base + VM_STACK_SIZE;
if (!script_instantiate(s, 0)) {
sciprintf("game_init(): Could not instantiate script 0\n");
warning("game_init(): Could not instantiate script 0");
return 1;
}
@ -568,13 +568,12 @@ int game_init(EngineState *s) {
const char *tmp = obj_get_name(s, game_obj);
if (!tmp) {
sciprintf("Error: script.000, export 0 (%04x:%04x) does not\n"
" yield an object with a name -> sanity check failed\n", PRINT_REG(game_obj));
warning("Error: script.000, export 0 (%04x:%04x) does not yield an object with a name -> sanity check failed", PRINT_REG(game_obj));
return 1;
}
s->_gameName = tmp;
sciprintf(" \"%s\" at %04x:%04x\n", s->_gameName.c_str(), PRINT_REG(game_obj));
debug(2, " \"%s\" at %04x:%04x", s->_gameName.c_str(), PRINT_REG(game_obj));
s->game_obj = game_obj;
@ -603,7 +602,7 @@ int game_exit(EngineState *s) {
s->_synonyms.clear();
sciprintf("Freeing miscellaneous data...\n");
debug(2, "Freeing miscellaneous data...");
// TODO Free parser segment here

View file

@ -529,7 +529,7 @@ int kfree(EngineState *s, reg_t handle) {
// Alternative kernel func names retriever. Required for KQ1/SCI (at least).
static void _vocabulary_get_knames0alt(const Resource *r, Common::StringList &names) {
static void _vocab_get_knames0alt(const Resource *r, Common::StringList &names) {
uint idx = 0;
while (idx < r->size) {
@ -542,7 +542,7 @@ static void _vocabulary_get_knames0alt(const Resource *r, Common::StringList &na
names.push_back(SCRIPT_UNKNOWN_FUNCTION_STRING);
}
static void vocabulary_get_knames0(ResourceManager *resmgr, Common::StringList &names) {
static void vocab_get_knames0(ResourceManager *resmgr, Common::StringList &names) {
int count, i, index = 2, empty_to_add = 1;
Resource *r = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_KNAMES, 0);
@ -556,7 +556,7 @@ static void vocabulary_get_knames0(ResourceManager *resmgr, Common::StringList &
count = READ_LE_UINT16(r->data);
if (count > 1023) {
_vocabulary_get_knames0alt(r, names);
_vocab_get_knames0alt(r, names);
return;
}
@ -580,7 +580,7 @@ static void vocabulary_get_knames0(ResourceManager *resmgr, Common::StringList &
}
}
static void vocabulary_get_knames1(ResourceManager *resmgr, Common::StringList &names) {
static void vocab_get_knames1(ResourceManager *resmgr, Common::StringList &names) {
// vocab.999/999.voc is notoriously unreliable in SCI1 games, and should not be used
// We hardcode the default SCI1 kernel names here (i.e. the ones inside the "special"
// 999.voc file from FreeSCI). All SCI1 games seem to be working with this change, but
@ -595,7 +595,7 @@ static void vocabulary_get_knames1(ResourceManager *resmgr, Common::StringList &
}
#ifdef ENABLE_SCI32
static void vocabulary_get_knames11(ResourceManager *resmgr, Common::StringList &names) {
static void vocab_get_knames11(ResourceManager *resmgr, Common::StringList &names) {
/*
999.voc format for SCI1.1 games:
[b] # of kernel functions
@ -621,13 +621,13 @@ static void vocabulary_get_knames11(ResourceManager *resmgr, Common::StringList
}
#endif
void vocabulary_get_knames(ResourceManager *resmgr, Common::StringList &names) {
void vocab_get_knames(ResourceManager *resmgr, Common::StringList &names) {
names.clear();
switch (resmgr->_sciVersion) {
case SCI_VERSION_0:
case SCI_VERSION_01:
vocabulary_get_knames0(resmgr, names);
vocab_get_knames0(resmgr, names);
break;
case SCI_VERSION_01_VGA:
case SCI_VERSION_01_VGA_ODD:
@ -635,19 +635,19 @@ void vocabulary_get_knames(ResourceManager *resmgr, Common::StringList &names) {
// Having more vocabulary names (like in SCI1) doesn't seem to have any
// ill effects, other than resulting in unmapped functions towards the
// end, which are never used by the game interpreter anyway
// return vocabulary_get_knames0(resmgr, count);
// return vocab_get_knames0(resmgr, count);
case SCI_VERSION_1_EARLY:
case SCI_VERSION_1_LATE:
vocabulary_get_knames1(resmgr, names);
vocab_get_knames1(resmgr, names);
break;
case SCI_VERSION_1_1:
vocabulary_get_knames1(resmgr, names);
vocab_get_knames1(resmgr, names);
// KQ6CD calls unimplemented function 0x26
names[0x26] = "Dummy";
break;
#ifdef ENABLE_SCI32
case SCI_VERSION_32:
vocabulary_get_knames11(resmgr, names);
vocab_get_knames11(resmgr, names);
#endif
break;
default:

View file

@ -9,7 +9,6 @@ MODULE_OBJS = \
sci.o \
tools.o \
vocabulary.o \
vocab_debug.o \
engine/game.o \
engine/gc.o \
engine/grammar.o \

View file

@ -1,118 +0,0 @@
/* 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

View file

@ -43,8 +43,13 @@ int vocab_version;
VOCAB_RESOURCE_SCI0_SUFFIX_VOCAB
/*
// These strange names were taken from an SCI01 interpreter
#if 0
/**
* Vocabulary class names.
* These strange names were taken from an SCI01 interpreter.
*/
const char *class_names[] = {"",
"",
"conj", // conjunction
@ -62,7 +67,92 @@ const char *class_names[] = {"",
"",
""
};
*/
int *vocab_get_classes(ResourceManager *resmgr, int* count) {
Resource* r;
int *c;
unsigned int i;
if ((r = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_CLASSES, 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 vocab_get_class_count(ResourceManager *resmgr) {
Resource* r;
if ((r = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_CLASSES, 0)) == 0)
return 0;
return r->size / 4;
}
#endif
bool vocab_get_snames(ResourceManager *resmgr, bool isOldSci0, Common::StringList &selectorNames) {
int count;
Resource *r = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_SNAMES, 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 vocab_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";
}
}
bool vocab_get_words(ResourceManager *resmgr, WordMap &words) {

View file

@ -39,11 +39,11 @@ class ResourceManager;
/*#define VOCABULARY_DEBUG */
/** The string used to identify the "unknown" SCI0 function for each game */
#define SCRIPT_UNKNOWN_FUNCTION_STRING "[Unknown]"
/* The string used to identify the "unknown" SCI0 function for each game */
/** Number of bytes allocated on the heap to store bad words if parsing fails */
#define PARSE_HEAP_SIZE 64
/* Number of bytes allocated on the heap to store bad words if parsing fails */
struct opcode {
@ -52,17 +52,22 @@ struct opcode {
Common::String name;
};
#define VOCAB_RESOURCE_OPCODES 998
#define VOCAB_RESOURCE_KNAMES 999
enum {
VOCAB_RESOURCE_CLASSES = 996,
VOCAB_RESOURCE_SNAMES = 997,
VOCAB_RESOURCE_OPCODES = 998,
VOCAB_RESOURCE_KNAMES = 999,
#define VOCAB_RESOURCE_SCI0_MAIN_VOCAB 0
#define VOCAB_RESOURCE_SCI0_PARSE_TREE_BRANCHES 900
#define VOCAB_RESOURCE_SCI0_SUFFIX_VOCAB 901
VOCAB_RESOURCE_SCI0_MAIN_VOCAB = 0,
VOCAB_RESOURCE_SCI0_PARSE_TREE_BRANCHES = 900,
VOCAB_RESOURCE_SCI0_SUFFIX_VOCAB = 901,
VOCAB_RESOURCE_SCI1_MAIN_VOCAB = 900,
VOCAB_RESOURCE_SCI1_PARSE_TREE_BRANCHES = 901,
VOCAB_RESOURCE_SCI1_SUFFIX_VOCAB = 902,
VOCAB_RESOURCE_SCI1_CHAR_TRANSFORMS = 913
};
#define VOCAB_RESOURCE_SCI1_MAIN_VOCAB 900
#define VOCAB_RESOURCE_SCI1_PARSE_TREE_BRANCHES 901
#define VOCAB_RESOURCE_SCI1_SUFFIX_VOCAB 902
#define VOCAB_RESOURCE_SCI1_CHAR_TRANSFORMS 913
enum {
VOCAB_CLASS_PREPOSITION = 0x01,
@ -76,8 +81,6 @@ enum {
VOCAB_CLASS_NUMBER = 0x001
};
extern const char *class_names[]; /* Vocabulary class names */
#define VOCAB_CLASS_ANYWORD 0xff
/* Anywords are ignored by the parser */
@ -181,23 +184,16 @@ struct parse_tree_node_t {
/*FIXME: These need freeing functions...*/
#if 0
int *vocabulary_get_classes(ResourceManager *resmgr, int *count);
int vocabulary_get_class_count(ResourceManager *resmgr);
#endif
/**
* Fills the given StringList with selector names.
* Returns true upon success, false oterwise.
*/
bool vocabulary_get_snames(ResourceManager *resmgr, bool isOldSci0, Common::StringList &selectorNames);
bool vocab_get_snames(ResourceManager *resmgr, bool isOldSci0, Common::StringList &selectorNames);
/**
* Obtain the list of opcodes.
*/
void vocabulary_get_opcodes(ResourceManager *resmgr, Common::Array<opcode> &opcodes);
void vocab_get_opcodes(ResourceManager *resmgr, Common::Array<opcode> &opcodes);
/**
* Fills a StringList with kernel function names.
@ -207,7 +203,7 @@ void vocabulary_get_opcodes(ResourceManager *resmgr, Common::Array<opcode> &opco
* The resulting list has the same format regardless of the format of the
* name table of the resource (the format changed between version 0 and 1).
*/
void vocabulary_get_knames(ResourceManager *resmgr, Common::StringList &names);
void vocab_get_knames(ResourceManager *resmgr, Common::StringList &names);
/**