aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMax Horn2009-09-22 01:08:42 +0000
committerMax Horn2009-09-22 01:08:42 +0000
commitc5cc78580253968ae3cfe2dddbce9b8b7b388f65 (patch)
treec93e16e023ec950bee679c9c0ca875c5bc1d0eed /engines
parent6424a1e9e254798bdc31ec32e6b754805681d116 (diff)
downloadscummvm-rg350-c5cc78580253968ae3cfe2dddbce9b8b7b388f65.tar.gz
scummvm-rg350-c5cc78580253968ae3cfe2dddbce9b8b7b388f65.tar.bz2
scummvm-rg350-c5cc78580253968ae3cfe2dddbce9b8b7b388f65.zip
SCI: Change SystemStrings to use RAW storage consistenly
svn-id: r44246
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/engine/game.cpp26
-rw-r--r--engines/sci/engine/savegame.cpp37
-rw-r--r--engines/sci/engine/segment.cpp8
-rw-r--r--engines/sci/engine/segment.h18
-rw-r--r--engines/sci/engine/vm.h7
-rw-r--r--engines/sci/sci.cpp2
6 files changed, 33 insertions, 65 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index f77cff4b95..821ae7e4e0 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -334,12 +334,10 @@ int script_init_engine(EngineState *s) {
s->string_frag_segment = s->segMan->allocateStringFrags();
// Allocate static buffer for savegame and CWD directories
- SystemString *str = &s->sys_strings->strings[SYS_STRING_SAVEDIR];
+ SystemString *str = &s->sys_strings->_strings[SYS_STRING_SAVEDIR];
str->_name = "savedir";
- str->max_size = MAX_SAVE_DIR_SIZE;
- str->value = (reg_t *)calloc(MAX_SAVE_DIR_SIZE, sizeof(reg_t)); // FIXME -- sizeof(char) or sizeof(reg_t) ??
- str->value[0].segment = s->string_frag_segment; // Set to empty string
- str->value[0].offset = 0;
+ str->_maxSize = MAX_SAVE_DIR_SIZE;
+ str->_value = (char *)calloc(MAX_SAVE_DIR_SIZE, sizeof(char));
s->r_acc = s->r_prev = NULL_REG;
@@ -365,16 +363,6 @@ int script_init_engine(EngineState *s) {
return 0;
}
-void script_set_gamestate_save_dir(EngineState *s, const char *path) {
- SystemString *str = &s->sys_strings->strings[SYS_STRING_SAVEDIR];
-
- strncpy((char *)str->value, path, str->max_size); // FIXME -- strncpy or internal_stringfrag_strncpy ?
- str->value[str->max_size - 1].segment = s->string_frag_segment; // Make sure to terminate
- str->value[str->max_size - 1].offset &= 0xff00; // Make sure to terminate
-}
-
-void internal_stringfrag_strncpy(EngineState *s, reg_t *dest, reg_t *src, int len);
-
void script_free_vm_memory(EngineState *s) {
debug(2, "Freeing VM memory");
@@ -438,12 +426,10 @@ int game_init(EngineState *s) {
s->status_bar_foreground = 0;
s->status_bar_background = !s->resMan->isVGA() ? 15 : 255;
- SystemString *str = &s->sys_strings->strings[SYS_STRING_PARSER_BASE];
+ SystemString *str = &s->sys_strings->_strings[SYS_STRING_PARSER_BASE];
str->_name = "parser-base";
- str->max_size = MAX_PARSER_BASE;
- str->value = (reg_t *)calloc(MAX_PARSER_BASE + 1, sizeof(char)); // FIXME -- sizeof(char) or sizeof(reg_t) ??
- str->value[0].segment = s->string_frag_segment; // Set to empty string
- str->value[0].offset = 0; // Set to empty string
+ str->_maxSize = MAX_PARSER_BASE;
+ str->_value = (char *)calloc(MAX_PARSER_BASE, sizeof(char));
s->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE);
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index c779e32fa9..7126037c7b 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -438,16 +438,24 @@ void Script::saveLoadWithSerializer(Common::Serializer &s) {
static void sync_SystemString(Common::Serializer &s, SystemString &obj) {
s.syncString(obj._name);
- s.syncAsSint32LE(obj.max_size);
+ s.syncAsSint32LE(obj._maxSize);
- // FIXME: This is a *WEIRD* hack: We sync a reg_t* as if it was a string.
- // No idea why, but this mimicks what the old save/load code used to do.
- syncCStr(s, (char **)&obj.value);
+ // Sync obj._value. We cannot use syncCStr as we must make sure that
+ // the allocated buffer has the correct size, i.e., obj._maxSize
+ Common::String tmp;
+ if (s.isSaving() && obj._value)
+ tmp = obj._value;
+ s.syncString(tmp);
+ if (s.isLoading()) {
+ //free(*str);
+ obj._value = (char *)calloc(obj._maxSize, sizeof(char));
+ strncpy(obj._value, tmp.c_str(), obj._maxSize);
+ }
}
void SystemStrings::saveLoadWithSerializer(Common::Serializer &s) {
for (int i = 0; i < SYS_STRINGS_MAX; ++i)
- sync_SystemString(s, strings[i]);
+ sync_SystemString(s, _strings[i]);
}
void DynMem::saveLoadWithSerializer(Common::Serializer &s) {
@@ -776,25 +784,6 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
retval->sys_strings_segment = retval->segMan->findSegmentByType(SEG_TYPE_SYS_STRINGS);
retval->sys_strings = (SystemStrings *)GET_SEGMENT(*retval->segMan, retval->sys_strings_segment, SEG_TYPE_SYS_STRINGS);
- // Restore system strings
- SystemString *str;
-
- // First, pad memory
- for (int i = 0; i < SYS_STRINGS_MAX; i++) {
- str = &retval->sys_strings->strings[i];
- char *data = (char *)str->value;
- if (data) {
- str->value = (reg_t *)calloc(str->max_size + 1, sizeof(reg_t));
- strncpy((char *)str->value, data, str->max_size + 1); // FIXME -- strncpy or internal_stringfrag_strncpy ?
- free(data);
- }
- }
-
- str = &retval->sys_strings->strings[SYS_STRING_SAVEDIR];
- internal_stringfrag_strncpy(s, str->value, s->sys_strings->strings[SYS_STRING_SAVEDIR].value, str->max_size);
- str->value[str->max_size - 1].segment = s->string_frag_segment; // Make sure to terminate
- str->value[str->max_size - 1].offset &= 0xff00; // Make sure to terminate
-
// Time state:
retval->last_wait_time = g_system->getMillis();
retval->game_start_time = g_system->getMillis() - retval->game_time * 1000;
diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp
index bf4b8bfea0..5410d82c24 100644
--- a/engines/sci/engine/segment.cpp
+++ b/engines/sci/engine/segment.cpp
@@ -294,15 +294,15 @@ SegmentRef DynMem::dereference(reg_t pointer) {
}
bool SystemStrings::isValidOffset(uint16 offset) const {
- return offset < SYS_STRINGS_MAX && !strings[offset]._name.empty();
+ return offset < SYS_STRINGS_MAX && !_strings[offset]._name.empty();
}
SegmentRef SystemStrings::dereference(reg_t pointer) {
SegmentRef ret;
- ret.isRaw = false; // FIXME: Raw or not raw? the sys strings code is totally incoherent in this regard
- ret.maxSize = strings[pointer.offset].max_size;
+ ret.isRaw = true; // FIXME: Raw or not raw? the sys strings code is totally incoherent in this regard
+ ret.maxSize = _strings[pointer.offset]._maxSize;
if (isValidOffset(pointer.offset))
- ret.raw = (byte *)(strings[pointer.offset].value);
+ ret.raw = (byte *)(_strings[pointer.offset]._value);
else {
// This occurs in KQ5CD when interacting with certain objects
warning("Attempt to dereference invalid pointer %04x:%04x", PRINT_REG(pointer));
diff --git a/engines/sci/engine/segment.h b/engines/sci/engine/segment.h
index 1f446957d5..f7d42894ad 100644
--- a/engines/sci/engine/segment.h
+++ b/engines/sci/engine/segment.h
@@ -150,28 +150,28 @@ enum {
struct SystemString {
Common::String _name;
- int max_size;
- reg_t *value;
+ int _maxSize;
+ char *_value;
};
struct SystemStrings : public SegmentObj {
- SystemString strings[SYS_STRINGS_MAX];
+ SystemString _strings[SYS_STRINGS_MAX];
public:
SystemStrings() : SegmentObj(SEG_TYPE_SYS_STRINGS) {
for (int i = 0; i < SYS_STRINGS_MAX; i++) {
- strings[i].max_size = 0;
- strings[i].value = 0;
+ _strings[i]._maxSize = 0;
+ _strings[i]._value = 0;
}
}
~SystemStrings() {
for (int i = 0; i < SYS_STRINGS_MAX; i++) {
- SystemString *str = &strings[i];
+ SystemString *str = &_strings[i];
if (!str->_name.empty()) {
- free(str->value);
- str->value = NULL;
+ free(str->_value);
+ str->_value = NULL;
- str->max_size = 0;
+ str->_maxSize = 0;
}
}
}
diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h
index f712193753..c701634bc9 100644
--- a/engines/sci/engine/vm.h
+++ b/engines/sci/engine/vm.h
@@ -418,13 +418,6 @@ void script_debug(EngineState *s, bool bp);
int script_init_engine(EngineState *);
/**
- * Sets the gamestate's save_dir to the parameter path
- * @param[in] s The state to set
- * @param[in] path Path where save_dir will point to
- */
-void script_set_gamestate_save_dir(EngineState *s, const char *path);
-
-/**
* Frees all additional memory associated with a EngineState block
* @param[in] s The EngineState whose elements should be cleared
*/
diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp
index 507b666c99..ebba1b08f6 100644
--- a/engines/sci/sci.cpp
+++ b/engines/sci/sci.cpp
@@ -153,7 +153,7 @@ Common::Error SciEngine::run() {
// Set the savegame dir (actually, we set it to a fake value,
// since we cannot let the game control where saves are stored)
- script_set_gamestate_save_dir(_gamestate, "/");
+ strcpy(_gamestate->sys_strings->_strings[SYS_STRING_SAVEDIR]._value, "/");
GfxState gfx_state;
_gamestate->gfx_state = &gfx_state;