aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine
diff options
context:
space:
mode:
authorFilippos Karapetis2010-06-01 14:41:48 +0000
committerFilippos Karapetis2010-06-01 14:41:48 +0000
commite083c20da1aab0090a5fc3ea624c9810c63dad52 (patch)
tree8afe1c12bdba317e799049cdd49dec49281e728f /engines/sci/engine
parent400542a1fe688bb702a89333c833bc1d89dd1ed4 (diff)
downloadscummvm-rg350-e083c20da1aab0090a5fc3ea624c9810c63dad52.tar.gz
scummvm-rg350-e083c20da1aab0090a5fc3ea624c9810c63dad52.tar.bz2
scummvm-rg350-e083c20da1aab0090a5fc3ea624c9810c63dad52.zip
The system strings segment is a fixed segment of the segment manager, which doesn't change during the game, thus move all the system strings code and variables inside the segment manager
svn-id: r49372
Diffstat (limited to 'engines/sci/engine')
-rw-r--r--engines/sci/engine/game.cpp15
-rw-r--r--engines/sci/engine/kernel32.cpp14
-rw-r--r--engines/sci/engine/kfile.cpp2
-rw-r--r--engines/sci/engine/savegame.cpp4
-rw-r--r--engines/sci/engine/seg_manager.cpp24
-rw-r--r--engines/sci/engine/seg_manager.h21
-rw-r--r--engines/sci/engine/state.cpp3
-rw-r--r--engines/sci/engine/state.h4
8 files changed, 44 insertions, 43 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index 232e0eca55..02e66f2142 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -67,13 +67,7 @@ int script_init_engine(EngineState *s) {
s->script_000 = s->_segMan->getScript(script_000_segment);
- s->sys_strings = s->_segMan->allocateSysStrings(&s->sys_strings_segment);
-
- // Allocate static buffer for savegame and CWD directories
- SystemString *str = &s->sys_strings->_strings[SYS_STRING_SAVEDIR];
- str->_name = "savedir";
- str->_maxSize = MAX_SAVE_DIR_SIZE;
- str->_value = (char *)calloc(MAX_SAVE_DIR_SIZE, sizeof(char));
+ s->_segMan->initSysStrings();
s->r_acc = s->r_prev = NULL_REG;
s->restAdjust = 0;
@@ -108,7 +102,7 @@ int game_init(EngineState *s) {
if (s->_voc) {
s->_voc->parserIsValid = false; // Invalidate parser
s->_voc->parser_event = NULL_REG; // Invalidate parser event
- s->_voc->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE);
+ s->_voc->parser_base = make_reg(s->_segMan->getSysStringsSegment(), SYS_STRING_PARSER_BASE);
}
// Initialize menu TODO: Actually this should be another init()
@@ -117,11 +111,6 @@ int game_init(EngineState *s) {
s->successor = NULL; // No successor
- SystemString *str = &s->sys_strings->_strings[SYS_STRING_PARSER_BASE];
- str->_name = "parser-base";
- str->_maxSize = MAX_PARSER_BASE;
- str->_value = (char *)calloc(MAX_PARSER_BASE, sizeof(char));
-
s->game_start_time = g_system->getMillis();
s->last_wait_time = s->game_start_time;
diff --git a/engines/sci/engine/kernel32.cpp b/engines/sci/engine/kernel32.cpp
index b705bbb794..3dd596494d 100644
--- a/engines/sci/engine/kernel32.cpp
+++ b/engines/sci/engine/kernel32.cpp
@@ -575,16 +575,16 @@ reg_t kString(EngineState *s, int argc, reg_t *argv) {
uint32 count = argv[5].toSint16() == -1 ? string2.size() - index2 + 1 : argv[5].toUint16();
// We have a special case here for argv[1] being a system string
- if (argv[1].segment == s->sys_strings_segment) {
+ if (argv[1].segment == s->_segMan->getSysStringsSegment()) {
// Resize if necessary
- if ((uint32)s->sys_strings->_strings[argv[1].toUint16()]._maxSize < index1 + count) {
- delete[] s->sys_strings->_strings[argv[1].toUint16()]._value;
- s->sys_strings->_strings[argv[1].toUint16()]._maxSize = index1 + count;
- s->sys_strings->_strings[argv[1].toUint16()]._value = new char[index1 + count];
- memset(s->sys_strings->_strings[argv[1].toUint16()]._value, 0, index1 + count);
+ if ((uint32)s->_segMan->sysStrings->_strings[argv[1].toUint16()]._maxSize < index1 + count) {
+ delete[] s->_segMan->sysStrings->_strings[argv[1].toUint16()]._value;
+ s->_segMan->sysStrings->_strings[argv[1].toUint16()]._maxSize = index1 + count;
+ s->_segMan->sysStrings->_strings[argv[1].toUint16()]._value = new char[index1 + count];
+ memset(s->_segMan->sysStrings->_strings[argv[1].toUint16()]._value, 0, index1 + count);
}
- strncpy(s->sys_strings->_strings[argv[1].toUint16()]._value + index1, string2.c_str() + index2, count);
+ strncpy(s->_segMan->sysStrings->_strings[argv[1].toUint16()]._value + index1, string2.c_str() + index2, count);
} else {
SciString *string1 = s->_segMan->lookupString(argv[1]);
diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp
index e6b9a5388c..ba8714366f 100644
--- a/engines/sci/engine/kfile.cpp
+++ b/engines/sci/engine/kfile.cpp
@@ -428,7 +428,7 @@ reg_t kGetSaveDir(EngineState *s, int argc, reg_t *argv) {
warning("kGetSaveDir called with %d parameter(s): %04x:%04x", argc, PRINT_REG(argv[0]));
#endif
- return make_reg(s->sys_strings_segment, SYS_STRING_SAVEDIR);
+ return make_reg(s->_segMan->getSysStringsSegment(), SYS_STRING_SAVEDIR);
}
reg_t kCheckFreeSpace(EngineState *s, int argc, reg_t *argv) {
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index 20bcb687d5..85c9915d57 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -893,8 +893,6 @@ void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
retval->_gameObj = s->_gameObj;
retval->script_000 = retval->_segMan->getScript(retval->_segMan->getScriptSegment(0, SCRIPT_GET_DONT_LOAD));
retval->gc_countdown = GC_INTERVAL - 1;
- retval->sys_strings_segment = retval->_segMan->findSegmentByType(SEG_TYPE_SYS_STRINGS);
- retval->sys_strings = (SystemStrings *)(retval->_segMan->_heap[retval->sys_strings_segment]);
// Time state:
retval->last_wait_time = g_system->getMillis();
@@ -903,7 +901,7 @@ void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
// static parser information:
if (retval->_voc)
- retval->_voc->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE);
+ retval->_voc->parser_base = make_reg(s->_segMan->getSysStringsSegment(), SYS_STRING_PARSER_BASE);
retval->successor = NULL;
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index 92eb1c4717..4d3e6f754e 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -54,7 +54,6 @@ SegManager::SegManager(ResourceManager *resMan) {
createClassTable();
}
-// Destroy the object, free the memorys if allocated before
SegManager::~SegManager() {
resetSegMan();
}
@@ -81,6 +80,25 @@ void SegManager::resetSegMan() {
createClassTable();
}
+void SegManager::initSysStrings() {
+ sysStrings = (SystemStrings *)allocSegment(new SystemStrings(), &sysStringsSegment);
+
+ // Allocate static buffer for savegame and CWD directories
+ SystemString *strSaveDir = &sysStrings->_strings[SYS_STRING_SAVEDIR];
+ strSaveDir->_name = "savedir";
+ strSaveDir->_maxSize = MAX_SAVE_DIR_SIZE;
+ strSaveDir->_value = (char *)calloc(MAX_SAVE_DIR_SIZE, sizeof(char));
+ // Set the savegame dir (actually, we set it to a fake value,
+ // since we cannot let the game control where saves are stored)
+ ::strcpy(strSaveDir->_value, "");
+
+ // Allocate static buffer for the parser base
+ SystemString *strParserBase = &sysStrings->_strings[SYS_STRING_PARSER_BASE];
+ strParserBase->_name = "parser-base";
+ strParserBase->_maxSize = MAX_PARSER_BASE;
+ strParserBase->_value = (char *)calloc(MAX_PARSER_BASE, sizeof(char));
+}
+
SegmentId SegManager::findFreeSegment() const {
// FIXME: This is a very crude approach: We find a free segment id by scanning
// from the start. This can be slow if the number of segments becomes large.
@@ -393,10 +411,6 @@ DataStack *SegManager::allocateStack(int size, SegmentId *segid) {
return retval;
}
-SystemStrings *SegManager::allocateSysStrings(SegmentId *segid) {
- return (SystemStrings *)allocSegment(new SystemStrings(), segid);
-}
-
void SegManager::freeHunkEntry(reg_t addr) {
if (addr.isNull()) {
warning("Attempt to free a Hunk from a null address");
diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h
index c3efd483c2..9312f51f9d 100644
--- a/engines/sci/engine/seg_manager.h
+++ b/engines/sci/engine/seg_manager.h
@@ -182,16 +182,11 @@ public:
// 5. System Strings
/**
- * Allocates a system string table
- * See also sys_string_acquire();
- * @param[in] segid Segment ID of the stack
- * @returns The physical stack
+ * Initializes the system string table.
*/
- SystemStrings *allocateSysStrings(SegmentId *segid);
+ void initSysStrings();
- // 5. System Strings
-
// 6, 7. Lists and Nodes
/**
@@ -441,6 +436,11 @@ public:
void setClassOffset(int index, reg_t offset) { _classTable[index].reg = offset; }
void resizeClassTable(uint32 size) { _classTable.resize(size); }
+ /**
+ * Obtains the system strings segment ID
+ */
+ SegmentId getSysStringsSegment() { return sysStringsSegment; }
+
public: // TODO: make private
Common::Array<SegmentObj *> _heap;
// Only accessible from saveLoadWithSerializer()
@@ -467,6 +467,13 @@ private:
SegmentId Nodes_seg_id; ///< ID of the (a) node segment
SegmentId Hunks_seg_id; ///< ID of the (a) hunk segment
+ /* System strings */
+ SegmentId sysStringsSegment;
+public: // TODO: make private. Only kString() needs direct access
+ SystemStrings *sysStrings;
+
+private:
+
#ifdef ENABLE_SCI32
SegmentId Arrays_seg_id;
SegmentId String_seg_id;
diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp
index c9398d7ed5..3c36a05c2f 100644
--- a/engines/sci/engine/state.cpp
+++ b/engines/sci/engine/state.cpp
@@ -94,9 +94,6 @@ EngineState::EngineState(Vocabulary *voc, SegManager *segMan)
script_000 = 0;
- sys_strings_segment = 0;
- sys_strings = 0;
-
_gameObj = NULL_REG;
gc_countdown = 0;
diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h
index ad9de9e13e..2025b49f51 100644
--- a/engines/sci/engine/state.h
+++ b/engines/sci/engine/state.h
@@ -160,10 +160,6 @@ public:
*/
void shrinkStackToBase();
- /* System strings */
- SegmentId sys_strings_segment;
- SystemStrings *sys_strings;
-
reg_t _gameObj; /**< Pointer to the game object */
int gc_countdown; /**< Number of kernel calls until next gc */