mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-13 12:39:56 +00:00
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
This commit is contained in:
parent
400542a1fe
commit
e083c20da1
@ -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;
|
||||
|
||||
|
@ -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]);
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 */
|
||||
|
@ -233,11 +233,6 @@ Common::Error SciEngine::run() {
|
||||
script_adjust_opcode_formats(_gamestate);
|
||||
_kernel->loadKernelNames(getGameID());
|
||||
|
||||
// Set the savegame dir (actually, we set it to a fake value,
|
||||
// since we cannot let the game control where saves are stored)
|
||||
assert(_gamestate->sys_strings->_strings[SYS_STRING_SAVEDIR]._value != 0);
|
||||
strcpy(_gamestate->sys_strings->_strings[SYS_STRING_SAVEDIR]._value, "");
|
||||
|
||||
SciVersion soundVersion = _features->detectDoSoundType();
|
||||
|
||||
_gamestate->_soundCmd = new SoundCommandParser(_resMan, segMan, _kernel, _audio, soundVersion);
|
||||
|
Loading…
Reference in New Issue
Block a user