diff options
author | Filippos Karapetis | 2009-08-25 08:38:14 +0000 |
---|---|---|
committer | Filippos Karapetis | 2009-08-25 08:38:14 +0000 |
commit | ed66cad6777a779f5cabeec037a24613da0134bf (patch) | |
tree | a63032758b32e3ada2ec0287033edfc5a17ee1c3 /engines/sci/engine | |
parent | bc20237ae37cf042a0f7c2c49cd0ca68ef76379b (diff) | |
download | scummvm-rg350-ed66cad6777a779f5cabeec037a24613da0134bf.tar.gz scummvm-rg350-ed66cad6777a779f5cabeec037a24613da0134bf.tar.bz2 scummvm-rg350-ed66cad6777a779f5cabeec037a24613da0134bf.zip |
- Simplified the parameters of some functions
- Replaced some EngineState parameters
- The SCI version is now obtained from the resource manager or the segment manager, thereby simplifying several functions
- Plugged 2 leaks in the fallback detector
- Renamed the segment manager and resource manager to "segmentManager" and "resourceManager" in all places, for consistency
svn-id: r43722
Diffstat (limited to 'engines/sci/engine')
28 files changed, 401 insertions, 398 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 994054f6a7..6f36e40440 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -43,7 +43,7 @@ int _reset_graphics_input(EngineState *s) { gfx_color_t transparent = { PaletteEntry(), 0, -1, -1, 0 }; debug(2, "Initializing graphics"); - if (s->resmgr->getViewType() == kViewEga) { + if (s->resourceManager->getViewType() == kViewEga) { for (int i = 0; i < 16; i++) { if (gfxop_set_color(s->gfx_state, &(s->ega_colors[i]), gfx_sci0_image_colors[sci0_palette][i].r, gfx_sci0_image_colors[sci0_palette][i].g, gfx_sci0_image_colors[sci0_palette][i].b, 0, -1, -1)) { @@ -62,13 +62,13 @@ int _reset_graphics_input(EngineState *s) { s->gfx_state->gfxResMan->setStaticPalette(gfxr_read_pal1_amiga(file)); file.close(); } else { - resource = s->resmgr->findResource(ResourceId(kResourceTypePalette, 999), 1); + resource = s->resourceManager->findResource(ResourceId(kResourceTypePalette, 999), 1); if (resource) { - if (s->_version < SCI_VERSION_1_1) + if (s->resourceManager->sciVersion() < SCI_VERSION_1_1) s->gfx_state->gfxResMan->setStaticPalette(gfxr_read_pal1(999, resource->data, resource->size)); else s->gfx_state->gfxResMan->setStaticPalette(gfxr_read_pal11(999, resource->data, resource->size)); - s->resmgr->unlockResource(resource); + s->resourceManager->unlockResource(resource); } else { debug(2, "Couldn't find the default palette!"); } @@ -94,7 +94,7 @@ int _reset_graphics_input(EngineState *s) { font_nr = -1; do { - resource = s->resmgr->testResource(ResourceId(kResourceTypeFont, ++font_nr)); + resource = s->resourceManager->testResource(ResourceId(kResourceTypeFont, ++font_nr)); } while ((!resource) && (font_nr < 65536)); if (!resource) { @@ -109,7 +109,7 @@ int _reset_graphics_input(EngineState *s) { s->iconbar_port = new GfxPort(s->visual, gfx_rect(0, 0, 320, 200), s->ega_colors[0], transparent); s->iconbar_port->_flags |= GFXW_FLAG_NO_IMPLICIT_SWITCH; - if (s->resmgr->isVGA()) { + if (s->resourceManager->isVGA()) { // This bit sets the foreground and background colors in VGA SCI games gfx_color_t fgcolor; gfx_color_t bgcolor; @@ -179,11 +179,11 @@ static void _free_graphics_input(EngineState *s) { } int game_init_sound(EngineState *s, int sound_flags) { - if (s->resmgr->sciVersion() > SCI_VERSION_0_LATE) + if (s->resourceManager->sciVersion() > SCI_VERSION_0_LATE) sound_flags |= SFX_STATE_FLAG_MULTIPLAY; s->sfx_init_flags = sound_flags; - s->_sound.sfx_init(s->resmgr, sound_flags); + s->_sound.sfx_init(s->resourceManager, sound_flags); return 0; } @@ -191,20 +191,20 @@ int game_init_sound(EngineState *s, int sound_flags) { // Architectural stuff: Init/Unintialize engine int script_init_engine(EngineState *s) { s->kernel_opt_flags = 0; - s->seg_manager = new SegManager(s->resmgr, s->_version); + s->segmentManager = new SegManager(s->resourceManager); s->gc_countdown = GC_INTERVAL - 1; - SegmentId script_000_segment = s->seg_manager->getSegment(0, SCRIPT_GET_LOCK); + SegmentId script_000_segment = s->segmentManager->getSegment(0, SCRIPT_GET_LOCK); if (script_000_segment <= 0) { debug(2, "Failed to instantiate script.000"); return 1; } - s->script_000 = s->seg_manager->getScript(script_000_segment); + s->script_000 = s->segmentManager->getScript(script_000_segment); - s->sys_strings = s->seg_manager->allocateSysStrings(&s->sys_strings_segment); - s->string_frag_segment = s->seg_manager->allocateStringFrags(); + s->sys_strings = s->segmentManager->allocateSysStrings(&s->sys_strings_segment); + s->string_frag_segment = s->segmentManager->allocateStringFrags(); // Allocate static buffer for savegame and CWD directories SystemString *str = &s->sys_strings->strings[SYS_STRING_SAVEDIR]; @@ -227,9 +227,9 @@ int script_init_engine(EngineState *s) { s->have_bp = 0; if (((SciEngine*)g_engine)->getKernel()->hasLofsAbsolute()) - s->seg_manager->setExportWidth(1); + s->segmentManager->setExportWidth(1); else - s->seg_manager->setExportWidth(0); + s->segmentManager->setExportWidth(0); debug(2, "Engine initialized"); @@ -252,8 +252,8 @@ void internal_stringfrag_strncpy(EngineState *s, reg_t *dest, reg_t *src, int le void script_free_vm_memory(EngineState *s) { debug(2, "Freeing VM memory"); - if (s->seg_manager) - s->seg_manager->_classtable.clear(); + if (s->segmentManager) + s->segmentManager->_classtable.clear(); // Close all opened file handles s->_fileHandles.clear(); @@ -290,11 +290,11 @@ int game_init(EngineState *s) { // FIXME Use new VM instantiation code all over the place" DataStack *stack; - stack = s->seg_manager->allocateStack(VM_STACK_SIZE, &s->stack_segment); + stack = s->segmentManager->allocateStack(VM_STACK_SIZE, &s->stack_segment); s->stack_base = stack->entries; s->stack_top = s->stack_base + VM_STACK_SIZE; - if (!script_instantiate(s->resmgr, s->seg_manager, s->_version, 0)) { + if (!script_instantiate(s->resourceManager, s->segmentManager, 0)) { warning("game_init(): Could not instantiate script 0"); return 1; } @@ -310,7 +310,7 @@ int game_init(EngineState *s) { s->successor = NULL; // No successor s->_statusBarText.clear(); // Status bar is blank s->status_bar_foreground = 0; - s->status_bar_background = !s->resmgr->isVGA() ? 15 : 255; + s->status_bar_background = !s->resourceManager->isVGA() ? 15 : 255; SystemString *str = &s->sys_strings->strings[SYS_STRING_PARSER_BASE]; str->name = strdup("parser-base"); @@ -328,8 +328,8 @@ int game_init(EngineState *s) { // script_dissect(0, s->_selectorNames); // The first entry in the export table of script 0 points to the game object - s->game_obj = script_lookup_export(s->seg_manager, 0, 0); - s->_gameName = obj_get_name(s->seg_manager, s->_version, s->game_obj); + s->game_obj = script_lookup_export(s->segmentManager, 0, 0); + s->_gameName = obj_get_name(s->segmentManager, s->game_obj); debug(2, " \"%s\" at %04x:%04x", s->_gameName.c_str(), PRINT_REG(s->game_obj)); @@ -357,9 +357,9 @@ int game_exit(EngineState *s) { game_init_sound(s, SFX_STATE_FLAG_NOSOUND); } - s->seg_manager->_classtable.clear(); - delete s->seg_manager; - s->seg_manager = 0; + s->segmentManager->_classtable.clear(); + delete s->segmentManager; + s->segmentManager = 0; s->_synonyms.clear(); diff --git a/engines/sci/engine/gc.cpp b/engines/sci/engine/gc.cpp index 63a20ddf25..41d454d637 100644 --- a/engines/sci/engine/gc.cpp +++ b/engines/sci/engine/gc.cpp @@ -71,7 +71,7 @@ void add_outgoing_refs(void *refcon, reg_t addr) { } reg_t_hash_map *find_all_used_references(EngineState *s) { - SegManager *sm = s->seg_manager; + SegManager *sm = s->segmentManager; reg_t_hash_map *normal_map = NULL; WorklistManager wm; uint i; @@ -134,7 +134,7 @@ reg_t_hash_map *find_all_used_references(EngineState *s) { if (reg.segment != s->stack_segment) { // No need to repeat this one debugC(2, kDebugLevelGC, "[GC] Checking %04x:%04x\n", PRINT_REG(reg)); if (reg.segment < sm->_heap.size() && sm->_heap[reg.segment]) - sm->_heap[reg.segment]->listAllOutgoingReferences(s, reg, &wm, add_outgoing_refs); + sm->_heap[reg.segment]->listAllOutgoingReferences(reg, &wm, add_outgoing_refs, s->resourceManager->sciVersion()); } } @@ -145,7 +145,7 @@ reg_t_hash_map *find_all_used_references(EngineState *s) { } struct deallocator_t { - SegManager *segmgr; + SegManager *segManager; MemObject *mobj; #ifdef DEBUG_GC char *segnames[MEM_OBJ_MAX + 1]; @@ -160,7 +160,7 @@ void free_unless_used(void *refcon, reg_t addr) { if (!use_map->contains(addr)) { // Not found -> we can free it - deallocator->mobj->freeAtAddress(deallocator->segmgr, addr); + deallocator->mobj->freeAtAddress(deallocator->segManager, addr); #ifdef DEBUG_GC debugC(2, kDebugLevelGC, "[GC] Deallocating %04x:%04x\n", PRINT_REG(addr)); deallocator->segcount[deallocator->mobj->getType()]++; @@ -172,14 +172,14 @@ void free_unless_used(void *refcon, reg_t addr) { void run_gc(EngineState *s) { uint seg_nr; deallocator_t deallocator; - SegManager *sm = s->seg_manager; + SegManager *sm = s->segmentManager; #ifdef DEBUG_GC debugC(2, kDebugLevelGC, "[GC] Running...\n"); memset(&(deallocator.segcount), 0, sizeof(int) * (MEM_OBJ_MAX + 1)); #endif - deallocator.segmgr = sm; + deallocator.segManager = sm; deallocator.use_map = find_all_used_references(s); for (seg_nr = 1; seg_nr < sm->_heap.size(); seg_nr++) { diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp index 687e621405..013d8cb65b 100644 --- a/engines/sci/engine/kernel.cpp +++ b/engines/sci/engine/kernel.cpp @@ -363,7 +363,7 @@ static const char *argtype_description[] = { "Arithmetic" }; -Kernel::Kernel(ResourceManager *resmgr) : _resmgr(resmgr) { +Kernel::Kernel(ResourceManager *resourceManager) : _resourceManager(resourceManager) { memset(&_selectorMap, 0, sizeof(_selectorMap)); // FIXME: Remove this once/if we C++ify selector_map_t loadSelectorNames(); @@ -379,7 +379,7 @@ Kernel::~Kernel() { } void Kernel::detectSciFeatures() { - SciVersion version = _resmgr->sciVersion(); + SciVersion version = _resourceManager->sciVersion(); features = 0; @@ -421,7 +421,7 @@ void Kernel::detectSciFeatures() { } void Kernel::loadSelectorNames() { - Resource *r = _resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SNAMES), 0); + Resource *r = _resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SNAMES), 0); if (!r) { // No such resource? // Check if we have a table for this game @@ -433,7 +433,7 @@ void Kernel::loadSelectorNames() { for (uint32 i = 0; i < staticSelectorTable.size(); i++) { _selectorNames.push_back(staticSelectorTable[i]); - if (_resmgr->sciVersion() == SCI_VERSION_0_EARLY) + if (_resourceManager->sciVersion() == SCI_VERSION_0_EARLY) _selectorNames.push_back(staticSelectorTable[i]); } @@ -452,14 +452,14 @@ void Kernel::loadSelectorNames() { // 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 (_resmgr->sciVersion() == SCI_VERSION_0_EARLY) + if (_resourceManager->sciVersion() == SCI_VERSION_0_EARLY) _selectorNames.push_back(tmp); } } bool Kernel::loadOpcodes() { int count, i = 0; - Resource* r = _resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_OPCODES), 0); + Resource* r = _resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_OPCODES), 0); _opcodes.clear(); @@ -484,18 +484,18 @@ bool Kernel::loadOpcodes() { } // Allocates a set amount of memory for a specified use and returns a handle to it. -reg_t kalloc(EngineState *s, const char *type, int space) { +reg_t kalloc(SegManager *segManager, const char *type, int space) { reg_t reg; - s->seg_manager->alloc_hunk_entry(type, space, ®); + segManager->alloc_hunk_entry(type, space, ®); debugC(2, kDebugLevelMemory, "Allocated %d at hunk %04x:%04x (%s)\n", space, PRINT_REG(reg), type); return reg; } // Returns a pointer to the memory indicated by the specified handle -byte *kmem(EngineState *s, reg_t handle) { - HunkTable *ht = (HunkTable *)GET_SEGMENT(*s->seg_manager, handle.segment, MEM_OBJ_HUNK); +byte *kmem(SegManager *segManager, reg_t handle) { + HunkTable *ht = (HunkTable *)GET_SEGMENT(*segManager, handle.segment, MEM_OBJ_HUNK); if (!ht || !ht->isValidEntry(handle.offset)) { warning("Error: kmem() with invalid handle"); @@ -506,8 +506,8 @@ byte *kmem(EngineState *s, reg_t handle) { } // Frees the specified handle. Returns 0 on success, 1 otherwise. -int kfree(EngineState *s, reg_t handle) { - s->seg_manager->free_hunk_entry(handle); +int kfree(SegManager *segManager, reg_t handle) { + segManager->free_hunk_entry(handle); return 0; } @@ -649,7 +649,7 @@ void Kernel::mapFunctions() { return; } -int determine_reg_type(EngineState *s, reg_t reg, bool allow_invalid) { +int determine_reg_type(SegManager *segManager, reg_t reg, bool allow_invalid) { MemObject *mobj; int type = 0; @@ -661,12 +661,12 @@ int determine_reg_type(EngineState *s, reg_t reg, bool allow_invalid) { return type; } - if ((reg.segment >= s->seg_manager->_heap.size()) || !s->seg_manager->_heap[reg.segment]) + if ((reg.segment >= segManager->_heap.size()) || !segManager->_heap[reg.segment]) return 0; // Invalid - mobj = s->seg_manager->_heap[reg.segment]; + mobj = segManager->_heap[reg.segment]; - SciVersion version = s->_version; // for the offset defines + SciVersion version = segManager->sciVersion(); // for the offset defines switch (mobj->getType()) { case MEM_OBJ_SCRIPT: @@ -721,7 +721,7 @@ bool kernel_matches_signature(EngineState *s, const char *sig, int argc, const r while (*sig && argc) { if ((*sig & KSIG_ANY) != KSIG_ANY) { - int type = determine_reg_type(s, *argv, *sig & KSIG_ALLOW_INV); + int type = determine_reg_type(s->segmentManager, *argv, *sig & KSIG_ALLOW_INV); if (!type) { warning("[KERN] Could not determine type of ref %04x:%04x; failing signature check", PRINT_REG(*argv)); @@ -752,7 +752,7 @@ bool kernel_matches_signature(EngineState *s, const char *sig, int argc, const r static void *_kernel_dereference_pointer(EngineState *s, reg_t pointer, int entries, int align) { int maxsize; - void *retval = s->seg_manager->dereference(pointer, &maxsize); + void *retval = s->segmentManager->dereference(pointer, &maxsize); if (!retval) return NULL; @@ -781,7 +781,7 @@ reg_t *kernel_dereference_reg_pointer(EngineState *s, reg_t pointer, int entries void Kernel::setDefaultKernelNames() { _kernelNames = Common::StringList(sci_default_knames, SCI_KNAMES_DEFAULT_ENTRIES_NR); - switch (_resmgr->sciVersion()) { + switch (_resourceManager->sciVersion()) { case SCI_VERSION_0_EARLY: case SCI_VERSION_0_LATE: // Insert SCI0 file functions after SetCursor (0x28) @@ -817,7 +817,7 @@ void Kernel::setDefaultKernelNames() { } #ifdef ENABLE_SCI32 -//static void vocab_get_knames11(ResourceManager *resmgr, Common::StringList &names) { +//static void vocab_get_knames11(ResourceManager *resourceManager, Common::StringList &names) { /* 999.voc format for SCI1.1 games: [b] # of kernel functions @@ -829,7 +829,7 @@ void Kernel::setDefaultKernelNames() { */ /* //unsigned int size = 64, pos = 3; int len; - Resource *r = resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_KNAMES), 0); + Resource *r = resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_KNAMES), 0); if(r == NULL) // failed to open vocab.999 (happens with SCI1 demos) return; // FIXME: should return a default table for this engine const byte nCnt = *r->data; diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index a85025f514..3ad54c9d48 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -68,7 +68,7 @@ public: /** * Initializes the SCI kernel */ - Kernel(ResourceManager *resmgr); + Kernel(ResourceManager *resourceManager); ~Kernel(); uint getOpcodesSize() const { return _opcodes.size(); } @@ -95,16 +95,6 @@ public: bool hasKernelFunction(const char *functionName) const; /** - * Applies to all versions before 0.000.395 (i.e. KQ4 old, XMAS 1988 and LSL2). - * Old SCI versions used two word header for script blocks (first word equal - * to 0x82, meaning of the second one unknown). New SCI versions used one - * word header. - * Also, old SCI versions assign 120 degrees to left & right, and 60 to up - * and down. Later versions use an even 90 degree distribution. - */ - bool hasOldScriptHeader() const { return (features & kFeatureOldScriptHeader); } - - /** * Applies to all versions before 0.000.502 * Old SCI versions used to interpret the third DrawPic() parameter inversely, * with the opposite default value (obviously). @@ -177,7 +167,7 @@ private: */ bool loadOpcodes(); - ResourceManager *_resmgr; + ResourceManager *_resourceManager; uint32 features; // Kernel-related lists @@ -256,7 +246,7 @@ char *kernel_lookup_text(EngineState *s, reg_t address, int index); * @parm obj The address to check * @return True if it is an object, false otherwise */ -bool is_object(EngineState *s, reg_t obj); +bool is_object(SegManager *segManager, reg_t obj); /******************** Kernel function parameter macros ********************/ diff --git a/engines/sci/engine/kernel_types.h b/engines/sci/engine/kernel_types.h index 8927586a8e..c8281a1fdd 100644 --- a/engines/sci/engine/kernel_types.h +++ b/engines/sci/engine/kernel_types.h @@ -79,14 +79,14 @@ bool kernel_matches_signature(EngineState *s, const char *sig, int argc, const r /** * Determines the type of the object indicated by reg. - * @param s state to operate on + * @param segManager the Segment manager * @param reg register to check * @param allow_invalid determines whether invalid pointer (=offset) values are allowed * @return one of KSIG_* below KSIG_NULL. * KSIG_INVALID set if the type of reg can be determined, but is invalid. * 0 on error. */ -int determine_reg_type(EngineState *s, reg_t reg, bool allow_invalid); +int determine_reg_type(SegManager *segManager, reg_t reg, bool allow_invalid); /** * Returns a textual description of the type of an object. diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp index b3b8d3d53b..bac1d08d78 100644 --- a/engines/sci/engine/kevent.cpp +++ b/engines/sci/engine/kevent.cpp @@ -40,7 +40,7 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t obj = argv[1]; sci_event_t e; int oldx, oldy; - int modifier_mask = s->_version <= SCI_VERSION_01 ? SCI_EVM_ALL : SCI_EVM_NO_FOOLOCK; + int modifier_mask = s->resourceManager->sciVersion() <= SCI_VERSION_01 ? SCI_EVM_ALL : SCI_EVM_NO_FOOLOCK; // If there's a simkey pending, and the game wants a keyboard event, use the // simkey instead of a normal event diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index ffc14716a5..ab5cd57c34 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -203,8 +203,8 @@ int _find_priority_band(EngineState *s, int nr) { } reg_t graph_save_box(EngineState *s, rect_t area) { - reg_t handle = kalloc(s, "graph_save_box()", sizeof(gfxw_snapshot_t *)); - gfxw_snapshot_t **ptr = (gfxw_snapshot_t **)kmem(s, handle); + reg_t handle = kalloc(s->segmentManager, "graph_save_box()", sizeof(gfxw_snapshot_t *)); + gfxw_snapshot_t **ptr = (gfxw_snapshot_t **)kmem(s->segmentManager, handle); // FIXME: gfxw_make_snapshot returns a pointer. Now why do we store a // pointer to real memory inside the SCI heap? @@ -225,7 +225,7 @@ void graph_restore_box(EngineState *s, reg_t handle) { return; } - ptr = (gfxw_snapshot_t **)kmem(s, handle); + ptr = (gfxw_snapshot_t **)kmem(s->segmentManager, handle); if (!ptr) { warning("Attempt to restore invalid handle %04x:%04x", PRINT_REG(handle)); @@ -265,11 +265,11 @@ void graph_restore_box(EngineState *s, reg_t handle) { free(*ptr); *ptr = NULL; - kfree(s, handle); + kfree(s->segmentManager, handle); } PaletteEntry get_pic_color(EngineState *s, int color) { - if (!s->resmgr->isVGA()) + if (!s->resourceManager->isVGA()) return s->ega_colors[color].visual; if (color == -1 || color == 255) // -1 occurs in Eco Quest 1. Not sure if this is the best approach, but it seems to work @@ -286,7 +286,7 @@ PaletteEntry get_pic_color(EngineState *s, int color) { static gfx_color_t graph_map_color(EngineState *s, int color, int priority, int control) { gfx_color_t retval; - if (!s->resmgr->isVGA()) { + if (!s->resourceManager->isVGA()) { retval = s->ega_colors[(color >=0 && color < 16)? color : 0]; gfxop_set_color(s->gfx_state, &retval, (color < 0) ? -1 : retval.visual.r, retval.visual.g, retval.visual.b, (color == -1) ? 255 : 0, priority, control); @@ -302,11 +302,13 @@ static gfx_color_t graph_map_color(EngineState *s, int color, int priority, int } reg_t kSetCursor(EngineState *s, int funct_nr, int argc, reg_t *argv) { + SciVersion version = s->resourceManager->sciVersion(); + switch (argc) { case 1 : - if (s->_version < SCI_VERSION_1_LATE) { + if (version < SCI_VERSION_1_LATE) { GFX_ASSERT(gfxop_set_pointer_cursor(s->gfx_state, argv[0].toSint16())); - } else if (s->_version < SCI_VERSION_1_1) { + } else if (version < SCI_VERSION_1_1) { if (argv[0].toSint16() <= 1) { // Newer (SCI1.1) semantics: show/hide cursor CursorMan.showMouse(argv[0].toSint16() != 0); @@ -320,10 +322,10 @@ reg_t kSetCursor(EngineState *s, int funct_nr, int argc, reg_t *argv) { } break; case 2 : - if (s->_version < SCI_VERSION_1_LATE) { + if (version < SCI_VERSION_1_LATE) { GFX_ASSERT(gfxop_set_pointer_cursor(s->gfx_state, argv[1].toSint16() == 0 ? GFXOP_NO_POINTER : argv[0].toSint16())); - } else if (s->_version < SCI_VERSION_1_1) { + } else if (version < SCI_VERSION_1_1) { // Pre-SCI1.1: set cursor according to the first parameter, and toggle its // visibility based on the second parameter // Some late SCI1 games actually use the SCI1.1 version of this call (EcoQuest 1 @@ -502,7 +504,7 @@ reg_t kGraph(EngineState *s, int funct_nr, int argc, reg_t *argv) { case K_GRAPH_GET_COLORS_NR: - return make_reg(0, !s->resmgr->isVGA() ? 0x10 : 0x100); + return make_reg(0, !s->resourceManager->isVGA() ? 0x10 : 0x100); break; case K_GRAPH_DRAW_LINE: { @@ -691,13 +693,14 @@ void _k_dirloop(reg_t obj, uint16 angle, EngineState *s, int funct_nr, int argc, int signal = GET_SEL32V(obj, signal); int loop; int maxloops; + bool oldScriptHeader = (s->resourceManager->sciVersion() == SCI_VERSION_0_EARLY); if (signal & _K_VIEW_SIG_FLAG_DOESNT_TURN) return; angle %= 360; - if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) { + if (!oldScriptHeader) { if (angle < 45) loop = 3; else if (angle < 136) @@ -827,7 +830,7 @@ reg_t kCanBeHere(EngineState *s, int funct_nr, int argc, reg_t *argv) { while (widget) { if (widget->_ID && (widget->signal & _K_VIEW_SIG_FLAG_STOPUPD) && ((widget->_ID != obj.segment) || (widget->_subID != obj.offset)) - && is_object(s, make_reg(widget->_ID, widget->_subID))) + && is_object(s->segmentManager, make_reg(widget->_ID, widget->_subID))) if (collides_with(s, abs_zone, make_reg(widget->_ID, widget->_subID), 1, GASEOUS_VIEW_MASK_ACTIVE, funct_nr, argc, argv)) return not_register(s, NULL_REG); @@ -853,7 +856,7 @@ reg_t kCanBeHere(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t other_obj = node->value; debugC(2, kDebugLevelBresen, " comparing against %04x:%04x\n", PRINT_REG(other_obj)); - if (!is_object(s, other_obj)) { + if (!is_object(s->segmentManager, other_obj)) { warning("CanBeHere() cliplist contains non-object %04x:%04x", PRINT_REG(other_obj)); } else if (other_obj != obj) { // Clipping against yourself is not recommended @@ -1134,7 +1137,7 @@ Common::Rect set_base(EngineState *s, reg_t object) { void _k_base_setter(EngineState *s, reg_t object) { Common::Rect absrect = set_base(s, object); - if (lookup_selector(s, object, ((SciEngine*)g_engine)->getKernel()->_selectorMap.brLeft, NULL, NULL) != kSelectorVariable) + if (lookup_selector(s->segmentManager, object, ((SciEngine*)g_engine)->getKernel()->_selectorMap.brLeft, NULL, NULL) != kSelectorVariable) return; // non-fatal // Note: there was a check here for a very old version of SCI, which supposedly needed @@ -1142,7 +1145,7 @@ void _k_base_setter(EngineState *s, reg_t object) { // does not exist (earliest one was KQ4 SCI, version 0.000.274). This code is left here // for reference only #if 0 - if (s->_version <= SCI_VERSION_0) + if (s->resourceManager->sciVersion() <= SCI_VERSION_0) --absrect.top; // Compensate for early SCI OB1 'bug' #endif @@ -1239,7 +1242,7 @@ Common::Rect get_nsrect(EngineState *s, reg_t object, byte clip) { static void _k_set_now_seen(EngineState *s, reg_t object) { Common::Rect absrect = get_nsrect(s, object, 0); - if (lookup_selector(s, object, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsTop, NULL, NULL) != kSelectorVariable) { + if (lookup_selector(s->segmentManager, object, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsTop, NULL, NULL) != kSelectorVariable) { return; } // This isn't fatal @@ -1329,7 +1332,7 @@ static void _k_draw_control(EngineState *s, reg_t obj, int inverse); static void _k_disable_delete_for_now(EngineState *s, reg_t obj) { reg_t text_pos = GET_SEL32(obj, text); - char *text = text_pos.isNull() ? NULL : (char *)s->seg_manager->dereference(text_pos, NULL); + char *text = text_pos.isNull() ? NULL : (char *)s->segmentManager->dereference(text_pos, NULL); int type = GET_SEL32V(obj, type); int state = GET_SEL32V(obj, state); @@ -1353,7 +1356,7 @@ static void _k_disable_delete_for_now(EngineState *s, reg_t obj) { * that game - bringing the save/load dialog on a par with SCI0. */ if (type == K_CONTROL_BUTTON && text && (s->_gameName == "sq4") && - s->_version < SCI_VERSION_1_1 && !strcmp(text, " Delete ")) { + s->resourceManager->sciVersion() < SCI_VERSION_1_1 && !strcmp(text, " Delete ")) { PUT_SEL32V(obj, state, (state | kControlStateDisabled) & ~kControlStateEnabled); } } @@ -1418,7 +1421,7 @@ reg_t kEditControl(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t text_pos = GET_SEL32(obj, text); int display_offset = 0; - char *text = (char *)s->seg_manager->dereference(text_pos, NULL); + char *text = (char *)s->segmentManager->dereference(text_pos, NULL); int textlen; if (!text) { @@ -1580,7 +1583,7 @@ static void _k_draw_control(EngineState *s, reg_t obj, int inverse) { int font_nr = GET_SEL32V(obj, font); reg_t text_pos = GET_SEL32(obj, text); - const char *text = text_pos.isNull() ? NULL : (char *)s->seg_manager->dereference(text_pos, NULL); + const char *text = text_pos.isNull() ? NULL : (char *)s->segmentManager->dereference(text_pos, NULL); int view = GET_SEL32V(obj, view); int cel = sign_extend_byte(GET_SEL32V(obj, cel)); int loop = sign_extend_byte(GET_SEL32V(obj, loop)); @@ -1702,7 +1705,7 @@ static void draw_rect_to_control_map(EngineState *s, Common::Rect abs_zone) { static void draw_obj_to_control_map(EngineState *s, GfxDynView *view) { reg_t obj = make_reg(view->_ID, view->_subID); - if (!is_object(s, obj)) + if (!is_object(s->segmentManager, obj)) warning("View %d does not contain valid object reference %04x:%04x", view->_ID, PRINT_REG(obj)); reg_t* sp = view->signalp.getPointer(s); @@ -1725,7 +1728,7 @@ static void _k_view_list_do_postdraw(EngineState *s, GfxList *list) { * if ((widget->signal & (_K_VIEW_SIG_FLAG_PRIVATE | _K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_NO_UPDATE)) == _K_VIEW_SIG_FLAG_PRIVATE) { */ if ((widget->signal & (_K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_NO_UPDATE)) == 0) { - int has_nsrect = lookup_selector(s, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable; + int has_nsrect = lookup_selector(s->segmentManager, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable; if (has_nsrect) { int temp; @@ -1747,7 +1750,7 @@ static void _k_view_list_do_postdraw(EngineState *s, GfxList *list) { } #ifdef DEBUG_LSRECT else - fprintf(stderr, "Not lsRecting %04x:%04x because %d\n", PRINT_REG(obj), lookup_selector(s, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL)); + fprintf(stderr, "Not lsRecting %04x:%04x because %d\n", PRINT_REG(obj), lookup_selector(s->segmentManager, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL)); #endif if (widget->signal & _K_VIEW_SIG_FLAG_HIDDEN) @@ -1806,7 +1809,7 @@ int _k_view_list_dispose_loop(EngineState *s, List *list, GfxDynView *widget, in reg_t obj = make_reg(widget->_ID, widget->_subID); reg_t under_bits = NULL_REG; - if (!is_object(s, obj)) { + if (!is_object(s->segmentManager, obj)) { error("Non-object %04x:%04x present in view list during delete time", PRINT_REG(obj)); obj = NULL_REG; } else { @@ -1815,7 +1818,7 @@ int _k_view_list_dispose_loop(EngineState *s, List *list, GfxDynView *widget, in reg_t mem_handle = *ubp; if (mem_handle.segment) { - if (!kfree(s, mem_handle)) { + if (!kfree(s->segmentManager, mem_handle)) { *ubp = make_reg(0, widget->under_bits = 0); } else { warning("Treating viewobj %04x:%04x as no longer present", PRINT_REG(obj)); @@ -1824,7 +1827,7 @@ int _k_view_list_dispose_loop(EngineState *s, List *list, GfxDynView *widget, in } } } - if (is_object(s, obj)) { + if (is_object(s->segmentManager, obj)) { if (invoke_selector(INV_SEL(obj, delete_, kContinueOnInvalidSelector), 0)) warning("Object at %04x:%04x requested deletion, but does not have a delete funcselector", PRINT_REG(obj)); if (_k_animate_ran) { @@ -1924,7 +1927,7 @@ static GfxDynView *_k_make_dynview_obj(EngineState *s, reg_t obj, int options, i } ObjVarRef under_bitsp; - if (lookup_selector(s, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.underBits, &(under_bitsp), NULL) != kSelectorVariable) { + if (lookup_selector(s->segmentManager, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.underBits, &(under_bitsp), NULL) != kSelectorVariable) { under_bitsp.obj = NULL_REG; under_bits = NULL_REG; debugC(2, kDebugLevelGraphics, "Object at %04x:%04x has no underBits\n", PRINT_REG(obj)); @@ -1932,7 +1935,7 @@ static GfxDynView *_k_make_dynview_obj(EngineState *s, reg_t obj, int options, i under_bits = *under_bitsp.getPointer(s); ObjVarRef signalp; - if (lookup_selector(s, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.signal, &(signalp), NULL) != kSelectorVariable) { + if (lookup_selector(s->segmentManager, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.signal, &(signalp), NULL) != kSelectorVariable) { signalp.obj = NULL_REG; signal = 0; debugC(2, kDebugLevelGraphics, "Object at %04x:%04x has no signal selector\n", PRINT_REG(obj)); @@ -2025,7 +2028,7 @@ static void _k_prepare_view_list(EngineState *s, GfxList *list, int options) { while (view) { reg_t obj = make_reg(view->_ID, view->_subID); int priority, _priority; - int has_nsrect = (view->_ID <= 0) ? 0 : lookup_selector(s, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable; + int has_nsrect = (view->_ID <= 0) ? 0 : lookup_selector(s->segmentManager, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable; int oldsignal = view->signal; _k_set_now_seen(s, obj); @@ -2503,7 +2506,7 @@ reg_t kNewWindow(EngineState *s, int funct_nr, int argc, reg_t *argv) { int16 bgColor = (argc > 8 + argextra) ? argv[8 + argextra].toSint16() : 255; if (bgColor >= 0) { - if (!s->resmgr->isVGA()) + if (!s->resourceManager->isVGA()) bgcolor.visual = get_pic_color(s, MIN<int>(bgColor, 15)); else bgcolor.visual = get_pic_color(s, bgColor); @@ -2529,7 +2532,7 @@ reg_t kNewWindow(EngineState *s, int funct_nr, int argc, reg_t *argv) { black.alpha = 0; black.control = -1; black.priority = -1; - lWhite.visual = get_pic_color(s, !s->resmgr->isVGA() ? 15 : 255); + lWhite.visual = get_pic_color(s, !s->resourceManager->isVGA() ? 15 : 255); lWhite.mask = GFX_MASK_VISUAL; lWhite.alpha = 0; lWhite.priority = -1; @@ -3150,7 +3153,7 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) { bg_color = port->_bgcolor; // TODO: in SCI1VGA the default colors for text and background are #0 (black) // SCI0 case should be checked - if (s->resmgr->isVGA()) { + if (s->resourceManager->isVGA()) { // This priority check fixes the colors in the menus in KQ5 // TODO/FIXME: Is this correct? if (color0.priority >= 0) @@ -3192,10 +3195,10 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) { temp = argv[argpt++].toSint16(); debugC(2, kDebugLevelGraphics, "Display: set_color(%d)\n", temp); - if (!s->resmgr->isVGA() && temp >= 0 && temp <= 15) + if (!s->resourceManager->isVGA() && temp >= 0 && temp <= 15) color0 = (s->ega_colors[temp]); else - if (s->resmgr->isVGA() && temp >= 0 && temp < 256) { + if (s->resourceManager->isVGA() && temp >= 0 && temp < 256) { color0.visual = get_pic_color(s, temp); color0.mask = GFX_MASK_VISUAL; } else @@ -3209,10 +3212,10 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) { temp = argv[argpt++].toSint16(); debugC(2, kDebugLevelGraphics, "Display: set_bg_color(%d)\n", temp); - if (!s->resmgr->isVGA() && temp >= 0 && temp <= 15) + if (!s->resourceManager->isVGA() && temp >= 0 && temp <= 15) bg_color = s->ega_colors[temp]; else - if (s->resmgr->isVGA() && temp >= 0 && temp <= 256) { + if (s->resourceManager->isVGA() && temp >= 0 && temp <= 256) { bg_color.visual = get_pic_color(s, temp); bg_color.mask = GFX_MASK_VISUAL; } else diff --git a/engines/sci/engine/klists.cpp b/engines/sci/engine/klists.cpp index a9ae77972f..bdf9115c84 100644 --- a/engines/sci/engine/klists.cpp +++ b/engines/sci/engine/klists.cpp @@ -32,7 +32,7 @@ Node *lookup_node(EngineState *s, reg_t addr) { if (!addr.offset && !addr.segment) return NULL; // Non-error null - MemObject *mobj = GET_SEGMENT(*s->seg_manager, addr.segment, MEM_OBJ_NODES); + MemObject *mobj = GET_SEGMENT(*s->segmentManager, addr.segment, MEM_OBJ_NODES); if (!mobj) { // FIXME: This occurs right at the beginning of SQ4, when walking north from the first screen. It doesn't // seem to have any apparent ill-effects, though, so it's been changed to non-fatal, for now @@ -52,7 +52,7 @@ Node *lookup_node(EngineState *s, reg_t addr) { } List *lookup_list(EngineState *s, reg_t addr) { - MemObject *mobj = GET_SEGMENT(*s->seg_manager, addr.segment, MEM_OBJ_LISTS); + MemObject *mobj = GET_SEGMENT(*s->segmentManager, addr.segment, MEM_OBJ_LISTS); if (!mobj) { error("Attempt to use non-list %04x:%04x as list", PRINT_REG(addr)); @@ -135,7 +135,7 @@ int sane_listp(EngineState *s, reg_t addr) { reg_t kNewList(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t listbase; List *l; - l = s->seg_manager->alloc_List(&listbase); + l = s->segmentManager->alloc_List(&listbase); l->first = l->last = NULL_REG; debugC(2, kDebugLevelNodes, "New listbase at %04x:%04x\n", PRINT_REG(listbase)); @@ -159,19 +159,19 @@ reg_t kDisposeList(EngineState *s, int funct_nr, int argc, reg_t *argv) { while (!n_addr.isNull()) { // Free all nodes Node *n = lookup_node(s, n_addr); - s->seg_manager->free_Node(n_addr); + s->segmentManager->free_Node(n_addr); n_addr = n->succ; } } - s->seg_manager->free_list(argv[0]); + s->segmentManager->free_list(argv[0]); */ return s->r_acc; } reg_t _k_new_node(EngineState *s, reg_t value, reg_t key) { reg_t nodebase; - Node *n = s->seg_manager->alloc_Node(&nodebase); + Node *n = s->segmentManager->alloc_Node(&nodebase); if (!n) { error("[Kernel] Out of memory while creating a node"); @@ -401,7 +401,7 @@ reg_t kDeleteKey(EngineState *s, int funct_nr, int argc, reg_t *argv) { if (!n->succ.isNull()) lookup_node(s, n->succ)->pred = n->pred; - //s->seg_manager->free_Node(node_pos); + //s->segmentManager->free_Node(node_pos); return make_reg(0, 1); // Signal success } @@ -444,7 +444,7 @@ reg_t kSort(EngineState *s, int funct_nr, int argc, reg_t *argv) { return s->r_acc; if (output_data.isNull()) { - list = s->seg_manager->alloc_List(&output_data); + list = s->segmentManager->alloc_List(&output_data); list->first = list->last = NULL_REG; PUT_SEL32(dest, elements, output_data); } diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp index 90ae88b73f..7f6f95347b 100644 --- a/engines/sci/engine/kmisc.cpp +++ b/engines/sci/engine/kmisc.cpp @@ -180,16 +180,16 @@ enum { reg_t kMemory(EngineState *s, int funct_nr, int argc, reg_t *argv) { switch (argv[0].toUint16()) { case K_MEMORY_ALLOCATE_CRITICAL : - if (!s->seg_manager->allocDynmem(argv[1].toUint16(), "kMemory() critical", &s->r_acc)) { + if (!s->segmentManager->allocDynmem(argv[1].toUint16(), "kMemory() critical", &s->r_acc)) { error("Critical heap allocation failed"); } return s->r_acc; break; case K_MEMORY_ALLOCATE_NONCRITICAL : - s->seg_manager->allocDynmem(argv[1].toUint16(), "kMemory() non-critical", &s->r_acc); + s->segmentManager->allocDynmem(argv[1].toUint16(), "kMemory() non-critical", &s->r_acc); break; case K_MEMORY_FREE : - if (s->seg_manager->freeDynmem(argv[1])) { + if (s->segmentManager->freeDynmem(argv[1])) { error("Attempt to kMemory::free() non-dynmem pointer %04x:%04x", PRINT_REG(argv[1])); } break; @@ -219,7 +219,7 @@ reg_t kMemory(EngineState *s, int funct_nr, int argc, reg_t *argv) { warning("Attempt to peek invalid memory at %04x:%04x", PRINT_REG(argv[1])); return s->r_acc; } - if (s->seg_manager->_heap[argv[1].segment]->getType() == MEM_OBJ_LOCALS) + if (s->segmentManager->_heap[argv[1].segment]->getType() == MEM_OBJ_LOCALS) return *((reg_t *) ref); else return make_reg(0, (int16)READ_LE_UINT16(ref)); @@ -233,7 +233,7 @@ reg_t kMemory(EngineState *s, int funct_nr, int argc, reg_t *argv) { return s->r_acc; } - if (s->seg_manager->_heap[argv[1].segment]->getType() == MEM_OBJ_LOCALS) + if (s->segmentManager->_heap[argv[1].segment]->getType() == MEM_OBJ_LOCALS) *((reg_t *) ref) = argv[2]; else { if (argv[2].segment) { diff --git a/engines/sci/engine/kmovement.cpp b/engines/sci/engine/kmovement.cpp index 58dc3b73f1..2c0dd1500b 100644 --- a/engines/sci/engine/kmovement.cpp +++ b/engines/sci/engine/kmovement.cpp @@ -257,7 +257,7 @@ static void bresenham_autodetect(EngineState *s) { reg_t motion_class; if (!parse_reg_t(s, "?Motion", &motion_class)) { - Object *obj = obj_get(s->seg_manager, s->_version, motion_class); + Object *obj = obj_get(s->segmentManager, motion_class); reg_t fptr; byte *buf; @@ -267,14 +267,14 @@ static void bresenham_autodetect(EngineState *s) { return; } - if (lookup_selector(s, motion_class, ((SciEngine*)g_engine)->getKernel()->_selectorMap.doit, NULL, &fptr) != kSelectorMethod) { + if (lookup_selector(s->segmentManager, motion_class, ((SciEngine*)g_engine)->getKernel()->_selectorMap.doit, NULL, &fptr) != kSelectorMethod) { warning("bresenham_autodetect failed"); handle_movecnt = INCREMENT_MOVECNT; // Most games do this, so best guess return; } - buf = s->seg_manager->getScript(fptr.segment)->buf + fptr.offset; - handle_movecnt = (s->_version <= SCI_VERSION_01 || checksum_bytes(buf, 8) == 0x216) ? INCREMENT_MOVECNT : IGNORE_MOVECNT; + buf = s->segmentManager->getScript(fptr.segment)->buf + fptr.offset; + handle_movecnt = (s->segmentManager->sciVersion() <= SCI_VERSION_01 || checksum_bytes(buf, 8) == 0x216) ? INCREMENT_MOVECNT : IGNORE_MOVECNT; printf("b-moveCnt action based on checksum: %s\n", handle_movecnt == IGNORE_MOVECNT ? "ignore" : "increment"); } else { warning("bresenham_autodetect failed"); @@ -293,7 +293,7 @@ reg_t kDoBresen(EngineState *s, int funct_nr, int argc, reg_t *argv) { int completed = 0; int max_movcnt = GET_SEL32V(client, moveSpeed); - if (s->_version > SCI_VERSION_01) + if (s->resourceManager->sciVersion() > SCI_VERSION_01) signal &= ~_K_VIEW_SIG_FLAG_HIT_OBSTACLE; if (handle_movecnt == UNINITIALIZED) @@ -380,7 +380,7 @@ reg_t kDoBresen(EngineState *s, int funct_nr, int argc, reg_t *argv) { completed = 1; } - if (s->_version > SCI_VERSION_01) + if (s->resourceManager->sciVersion() > SCI_VERSION_01) if (completed) invoke_selector(INV_SEL(mover, moveDone, kStopOnInvalidSelector), 0); diff --git a/engines/sci/engine/kpathing.cpp b/engines/sci/engine/kpathing.cpp index ad14202257..8d6142166a 100644 --- a/engines/sci/engine/kpathing.cpp +++ b/engines/sci/engine/kpathing.cpp @@ -1588,7 +1588,7 @@ static reg_t output_path(PathfindingState *p, EngineState *s) { if (unreachable) { // If pathfinding failed we only return the path up to vertex_start - oref = s->seg_manager->allocDynmem(POLY_POINT_SIZE * 3, AVOIDPATH_DYNMEM_STRING, &output); + oref = s->segmentManager->allocDynmem(POLY_POINT_SIZE * 3, AVOIDPATH_DYNMEM_STRING, &output); if (p->_prependPoint) POLY_SET_POINT(oref, 0, *p->_prependPoint); @@ -1608,7 +1608,7 @@ static reg_t output_path(PathfindingState *p, EngineState *s) { } // Allocate memory for path, plus 3 extra for appended point, prepended point and sentinel - oref = s->seg_manager->allocDynmem(POLY_POINT_SIZE * (path_len + 3), AVOIDPATH_DYNMEM_STRING, &output); + oref = s->segmentManager->allocDynmem(POLY_POINT_SIZE * (path_len + 3), AVOIDPATH_DYNMEM_STRING, &output); int offset = 0; @@ -1700,7 +1700,7 @@ reg_t kAvoidPath(EngineState *s, int funct_nr, int argc, reg_t *argv) { printf("[avoidpath] Error: pathfinding failed for following input:\n"); print_input(s, poly_list, start, end, opt); printf("[avoidpath] Returning direct path from start point to end point\n"); - oref = s->seg_manager->allocDynmem(POLY_POINT_SIZE * 3, + oref = s->segmentManager->allocDynmem(POLY_POINT_SIZE * 3, AVOIDPATH_DYNMEM_STRING, &output); POLY_SET_POINT(oref, 0, start); diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp index 41eb9f624d..d59ed9b29d 100644 --- a/engines/sci/engine/kscripts.cpp +++ b/engines/sci/engine/kscripts.cpp @@ -34,7 +34,7 @@ namespace Sci { reg_t read_selector(EngineState *s, reg_t object, Selector selector_id, const char *file, int line) { ObjVarRef address; - if (lookup_selector(s, object, selector_id, &address, NULL) != kSelectorVariable) + if (lookup_selector(s->segmentManager, object, selector_id, &address, NULL) != kSelectorVariable) return NULL_REG; else return *address.getPointer(s); @@ -49,7 +49,7 @@ void write_selector(EngineState *s, reg_t object, Selector selector_id, reg_t va return; } - if (lookup_selector(s, object, selector_id, &address, NULL) != kSelectorVariable) + if (lookup_selector(s->segmentManager, object, selector_id, &address, NULL) != kSelectorVariable) warning("Selector '%s' of object at %04x:%04x could not be" " written to (%s L%d)", ((SciEngine*)g_engine)->getKernel()->getSelectorName(selector_id).c_str(), PRINT_REG(object), fname, line); else @@ -68,7 +68,7 @@ int invoke_selector(EngineState *s, reg_t object, int selector_id, SelectorInvoc stackframe[0] = make_reg(0, selector_id); // The selector we want to call stackframe[1] = make_reg(0, argc); // Argument count - slc_type = lookup_selector(s, object, selector_id, NULL, &address); + slc_type = lookup_selector(s->segmentManager, object, selector_id, NULL, &address); if (slc_type == kSelectorNone) { warning("Selector '%s' of object at %04x:%04x could not be invoked (%s L%d)", @@ -107,8 +107,8 @@ int invoke_selector(EngineState *s, reg_t object, int selector_id, SelectorInvoc return 0; } -bool is_object(EngineState *s, reg_t object) { - return obj_get(s->seg_manager, s->_version, object) != NULL; +bool is_object(SegManager *segManager, reg_t object) { + return obj_get(segManager, object) != NULL; } // Loads arbitrary resources of type 'restype' with resource numbers 'resnrs' @@ -119,7 +119,7 @@ reg_t kLoad(EngineState *s, int funct_nr, int argc, reg_t *argv) { // Request to dynamically allocate hunk memory for later use if (restype == kResourceTypeMemory) - return kalloc(s, "kLoad()", resnr); + return kalloc(s->segmentManager, "kLoad()", resnr); return make_reg(0, ((restype << 11) | resnr)); // Return the resource identifier as handle } @@ -133,18 +133,18 @@ reg_t kLock(EngineState *s, int funct_nr, int argc, reg_t *argv) { switch (state) { case 1 : - s->resmgr->findResource(id, 1); + s->resourceManager->findResource(id, 1); break; case 0 : - which = s->resmgr->findResource(id, 0); + which = s->resourceManager->findResource(id, 0); if (which) - s->resmgr->unlockResource(which); + s->resourceManager->unlockResource(which); else { if (id.type == kResourceTypeInvalid) - warning("[Resmgr] Attempt to unlock resource %i of invalid type %i", id.number, type); + warning("[resourceManager] Attempt to unlock resource %i of invalid type %i", id.number, type); else - warning("[Resmgr] Attempt to unlock non-existant resource %s", id.toString().c_str()); + warning("[resourceManager] Attempt to unlock non-existant resource %s", id.toString().c_str()); } break; } @@ -157,7 +157,7 @@ reg_t kUnLoad(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t resnr = argv[1]; if (restype == kResourceTypeMemory) - kfree(s, resnr); + kfree(s->segmentManager, resnr); return s->r_acc; } @@ -173,10 +173,10 @@ reg_t kResCheck(EngineState *s, int funct_nr, int argc, reg_t *argv) { uint cond = argv[4].toUint16() & 0xff; uint seq = argv[5].toUint16() & 0xff; - res = s->resmgr->testResource(ResourceId(restype, argv[1].toUint16(), noun, verb, cond, seq)); + res = s->resourceManager->testResource(ResourceId(restype, argv[1].toUint16(), noun, verb, cond, seq)); } } else { - res = s->resmgr->testResource(ResourceId(restype, argv[1].toUint16())); + res = s->resourceManager->testResource(ResourceId(restype, argv[1].toUint16())); } return make_reg(0, res != NULL); @@ -184,7 +184,7 @@ reg_t kResCheck(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t kClone(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t parent_addr = argv[0]; - Object *parent_obj = obj_get(s->seg_manager, s->_version, parent_addr); + Object *parent_obj = obj_get(s->segmentManager, parent_addr); reg_t clone_addr; Clone *clone_obj; // same as Object* @@ -195,7 +195,7 @@ reg_t kClone(EngineState *s, int funct_nr, int argc, reg_t *argv) { debugC(2, kDebugLevelMemory, "Attempting to clone from %04x:%04x\n", PRINT_REG(parent_addr)); - clone_obj = s->seg_manager->alloc_Clone(&clone_addr); + clone_obj = s->segmentManager->alloc_Clone(&clone_addr); if (!clone_obj) { error("Cloning %04x:%04x failed-- internal error", PRINT_REG(parent_addr)); @@ -205,15 +205,15 @@ reg_t kClone(EngineState *s, int funct_nr, int argc, reg_t *argv) { *clone_obj = *parent_obj; clone_obj->flags = 0; - SciVersion version = s->_version; // for the selector defines + SciVersion version = s->resourceManager->sciVersion(); // for the selector defines // Mark as clone clone_obj->_variables[SCRIPT_INFO_SELECTOR].offset = SCRIPT_INFO_CLONE; clone_obj->_variables[SCRIPT_SPECIES_SELECTOR] = clone_obj->pos; if (IS_CLASS(parent_obj)) clone_obj->_variables[SCRIPT_SUPERCLASS_SELECTOR] = parent_obj->pos; - s->seg_manager->getScript(parent_obj->pos.segment)->incrementLockers(); - s->seg_manager->getScript(clone_obj->pos.segment)->incrementLockers(); + s->segmentManager->getScript(parent_obj->pos.segment)->incrementLockers(); + s->segmentManager->getScript(clone_obj->pos.segment)->incrementLockers(); return clone_addr; } @@ -222,7 +222,7 @@ extern void _k_view_list_mark_free(EngineState *s, reg_t off); reg_t kDisposeClone(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t victim_addr = argv[0]; - Clone *victim_obj = obj_get(s->seg_manager, s->_version, victim_addr); + Clone *victim_obj = obj_get(s->segmentManager, victim_addr); uint16 underBits; if (!victim_obj) { @@ -231,7 +231,7 @@ reg_t kDisposeClone(EngineState *s, int funct_nr, int argc, reg_t *argv) { return s->r_acc; } - SciVersion version = s->_version; // for the selector defines + SciVersion version = s->resourceManager->sciVersion(); // for the selector defines if (victim_obj->_variables[SCRIPT_INFO_SELECTOR].offset != SCRIPT_INFO_CLONE) { //warning("Attempt to dispose something other than a clone at %04x", offset); @@ -264,7 +264,7 @@ reg_t kScriptID(EngineState *s, int funct_nr, int argc, reg_t *argv) { int script = argv[0].toUint16(); int index = (argc > 1) ? argv[1].toUint16() : 0; - SegmentId scriptid = s->seg_manager->getSegment(script, SCRIPT_GET_LOAD); + SegmentId scriptid = s->segmentManager->getSegment(script, SCRIPT_GET_LOAD); Script *scr; if (argv[0].segment) @@ -273,7 +273,7 @@ reg_t kScriptID(EngineState *s, int funct_nr, int argc, reg_t *argv) { if (!scriptid) return NULL_REG; - scr = s->seg_manager->getScript(scriptid); + scr = s->segmentManager->getScript(scriptid); if (!scr->exports_nr) { // FIXME: Is this fatal? This occurs in SQ4CD @@ -286,7 +286,7 @@ reg_t kScriptID(EngineState *s, int funct_nr, int argc, reg_t *argv) { return NULL_REG; } - return make_reg(scriptid, s->seg_manager->validateExportFunc(index, scriptid)); + return make_reg(scriptid, s->segmentManager->validateExportFunc(index, scriptid)); } reg_t kDisposeScript(EngineState *s, int funct_nr, int argc, reg_t *argv) { @@ -296,21 +296,21 @@ reg_t kDisposeScript(EngineState *s, int funct_nr, int argc, reg_t *argv) { if (argv[0].segment) return s->r_acc; - int id = s->seg_manager->segGet(script); - Script *scr = s->seg_manager->getScriptIfLoaded(id); + int id = s->segmentManager->segGet(script); + Script *scr = s->segmentManager->getScriptIfLoaded(id); if (scr) { if (s->_executionStack.back().addr.pc.segment != id) scr->setLockers(1); } - script_uninstantiate(s->seg_manager, s->_version, script); + script_uninstantiate(s->segmentManager, script); s->_executionStackPosChanged = true; return s->r_acc; } int is_heap_object(EngineState *s, reg_t pos) { - Object *obj = obj_get(s->seg_manager, s->_version, pos); - return (obj != NULL && (!(obj->flags & OBJECT_FLAG_FREED)) && (!s->seg_manager->scriptIsMarkedAsDeleted(pos.segment))); + Object *obj = obj_get(s->segmentManager, pos); + return (obj != NULL && (!(obj->flags & OBJECT_FLAG_FREED)) && (!s->segmentManager->scriptIsMarkedAsDeleted(pos.segment))); } reg_t kIsObject(EngineState *s, int funct_nr, int argc, reg_t *argv) { @@ -324,7 +324,7 @@ reg_t kRespondsTo(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t obj = argv[0]; int selector = argv[1].toUint16(); - return make_reg(0, is_heap_object(s, obj) && lookup_selector(s, obj, selector, NULL, NULL) != kSelectorNone); + return make_reg(0, is_heap_object(s, obj) && lookup_selector(s->segmentManager, obj, selector, NULL, NULL) != kSelectorNone); } } // End of namespace Sci diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp index 44b2404e41..06da533003 100644 --- a/engines/sci/engine/ksound.cpp +++ b/engines/sci/engine/ksound.cpp @@ -123,7 +123,7 @@ enum AudioSyncCommands { static void script_set_priority(EngineState *s, reg_t obj, int priority) { int song_nr = GET_SEL32V(obj, number); - Resource *song = s->resmgr->findResource(ResourceId(kResourceTypeSound, song_nr), 0); + Resource *song = s->resourceManager->findResource(ResourceId(kResourceTypeSound, song_nr), 0); int flags = GET_SEL32V(obj, flags); if (priority == -1) { @@ -140,7 +140,7 @@ static void script_set_priority(EngineState *s, reg_t obj, int priority) { } SongIterator *build_iterator(EngineState *s, int song_nr, SongIteratorType type, songit_id_t id) { - Resource *song = s->resmgr->findResource(ResourceId(kResourceTypeSound, song_nr), 0); + Resource *song = s->resourceManager->findResource(ResourceId(kResourceTypeSound, song_nr), 0); if (!song) return NULL; @@ -157,13 +157,13 @@ void process_sound_events(EngineState *s) { /* Get all sound events, apply their SongHandle handle; int cue; - if (s->_version > SCI_VERSION_01) + if (s->resourceManager->sciVersion() > SCI_VERSION_01) return; /* SCI1 and later explicitly poll for everything */ while ((result = s->_sound.sfx_poll(&handle, &cue))) { reg_t obj = DEFROBNICATE_HANDLE(handle); - if (!is_object(s, obj)) { + if (!is_object(s->segmentManager, obj)) { warning("Non-object %04x:%04x received sound signal (%d/%d)", PRINT_REG(obj), result, cue); return; } @@ -506,7 +506,7 @@ reg_t kDoSoundSci1Early(EngineState *s, int funct_nr, int argc, reg_t *argv) { //int vol = GET_SEL32V(obj, vol); //int pri = GET_SEL32V(obj, pri); - if (obj.segment && (s->resmgr->testResource(ResourceId(kResourceTypeSound, number)))) { + if (obj.segment && (s->resourceManager->testResource(ResourceId(kResourceTypeSound, number)))) { debugC(2, kDebugLevelSound, "Initializing song number %d\n", number); s->_sound.sfx_add_song(build_iterator(s, number, SCI_SONG_ITERATOR_TYPE_SCI1, handle), 0, handle, number); @@ -815,8 +815,8 @@ reg_t kDoSoundSci1Late(EngineState *s, int funct_nr, int argc, reg_t *argv) { // a relevant audio resource, play it, otherwise switch to synthesized // effects. If the resource exists, play it using map 65535 (sound // effects map) - if (s->resmgr->testResource(ResourceId(kResourceTypeAudio, number)) && - s->_version >= SCI_VERSION_1_1) { + if (s->resourceManager->testResource(ResourceId(kResourceTypeAudio, number)) && + s->resourceManager->sciVersion() >= SCI_VERSION_1_1) { // Found a relevant audio resource, play it s->_sound.stopAudio(); warning("Initializing audio resource instead of requested sound resource %d\n", number); @@ -824,7 +824,7 @@ reg_t kDoSoundSci1Late(EngineState *s, int funct_nr, int argc, reg_t *argv) { // Also create iterator, that will fire SI_FINISHED event, when the sound is done playing s->_sound.sfx_add_song(build_timeriterator(s, sampleLen), 0, handle, number); } else { - if (!s->resmgr->testResource(ResourceId(kResourceTypeSound, number))) { + if (!s->resourceManager->testResource(ResourceId(kResourceTypeSound, number))) { warning("Could not open song number %d", number); // Send a "stop handle" event so that the engine won't wait forever here s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED); @@ -858,7 +858,7 @@ reg_t kDoSoundSci1Late(EngineState *s, int funct_nr, int argc, reg_t *argv) { s->_sound.sfx_remove_song(handle); } - if (obj.segment && (s->resmgr->testResource(ResourceId(kResourceTypeSound, number)))) { + if (obj.segment && (s->resourceManager->testResource(ResourceId(kResourceTypeSound, number)))) { debugC(2, kDebugLevelSound, "Initializing song number %d\n", number); s->_sound.sfx_add_song(build_iterator(s, number, SCI_SONG_ITERATOR_TYPE_SCI1, handle), 0, handle, number); @@ -1051,7 +1051,7 @@ reg_t kDoAudio(EngineState *s, int funct_nr, int argc, reg_t *argv) { // In SCI1.1: tests for digital audio support return make_reg(0, 1); } else { - s->resmgr->setAudioLanguage(argv[1].toSint16()); + s->resourceManager->setAudioLanguage(argv[1].toSint16()); } break; default: @@ -1067,7 +1067,7 @@ reg_t kDoSync(EngineState *s, int funct_nr, int argc, reg_t *argv) { ResourceId id; if (s->_sound._syncResource) { - s->resmgr->unlockResource(s->_sound._syncResource); + s->resourceManager->unlockResource(s->_sound._syncResource); s->_sound._syncResource = NULL; } @@ -1082,7 +1082,7 @@ reg_t kDoSync(EngineState *s, int funct_nr, int argc, reg_t *argv) { return s->r_acc; } - s->_sound._syncResource = s->resmgr->findResource(id, 1); + s->_sound._syncResource = s->resourceManager->findResource(id, 1); if (s->_sound._syncResource) { PUT_SEL32V(argv[1], syncCue, 0); @@ -1114,7 +1114,7 @@ reg_t kDoSync(EngineState *s, int funct_nr, int argc, reg_t *argv) { } case kSciAudioSyncStop: if (s->_sound._syncResource) { - s->resmgr->unlockResource(s->_sound._syncResource); + s->resourceManager->unlockResource(s->_sound._syncResource); s->_sound._syncResource = NULL; } break; diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index 6e5a19bba9..7a936f3cb4 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -48,7 +48,7 @@ char *kernel_lookup_text(EngineState *s, reg_t address, int index) { else { int textlen; int _index = index; - textres = s->resmgr->findResource(ResourceId(kResourceTypeText, address.offset), 0); + textres = s->resourceManager->findResource(ResourceId(kResourceTypeText, address.offset), 0); if (!textres) { error("text.%03d not found", address.offset); @@ -144,15 +144,15 @@ reg_t kSetSynonyms(EngineState *s, int funct_nr, int argc, reg_t *argv) { int synonyms_nr = 0; script = GET_SEL32V(objpos, number); - seg = s->seg_manager->segGet(script); + seg = s->segmentManager->segGet(script); if (seg >= 0) - synonyms_nr = s->seg_manager->getScript(seg)->getSynonymsNr(); + synonyms_nr = s->segmentManager->getScript(seg)->getSynonymsNr(); if (synonyms_nr) { byte *synonyms; - synonyms = s->seg_manager->getScript(seg)->getSynonyms(); + synonyms = s->segmentManager->getScript(seg)->getSynonyms(); if (synonyms) { debugC(2, kDebugLevelParser, "Setting %d synonyms for script.%d\n", synonyms_nr, script); @@ -305,7 +305,7 @@ reg_t kStrCpy(EngineState *s, int funct_nr, int argc, reg_t *argv) { if (length >= 0) strncpy(dest, src, length); else { - if (s->seg_manager->_heap[argv[0].segment]->getType() == MEM_OBJ_DYNMEM) { + if (s->segmentManager->_heap[argv[0].segment]->getType() == MEM_OBJ_DYNMEM) { reg_t *srcp = (reg_t *) src; int i; @@ -368,7 +368,7 @@ reg_t kStrAt(EngineState *s, int funct_nr, int argc, reg_t *argv) { if ((argc == 2) && /* Our pathfinder already works around the issue we're trying to fix */ - (strcmp(s->seg_manager->getDescription(argv[0]), AVOIDPATH_DYNMEM_STRING) != 0) && + (strcmp(s->segmentManager->getDescription(argv[0]), AVOIDPATH_DYNMEM_STRING) != 0) && ((strlen(dst) < 2) || (!lsl5PasswordWorkaround && !is_print_str(dst)))) { // SQ4 array handling detected #ifndef SCUMM_BIG_ENDIAN @@ -642,7 +642,7 @@ reg_t kStrLen(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t kGetFarText(EngineState *s, int funct_nr, int argc, reg_t *argv) { - Resource *textres = s->resmgr->findResource(ResourceId(kResourceTypeText, argv[0].toUint16()), 0); + Resource *textres = s->resourceManager->findResource(ResourceId(kResourceTypeText, argv[0].toUint16()), 0); char *seeker; int counter = argv[1].toUint16(); @@ -713,7 +713,7 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t retval; if (func == K_MESSAGE_GET) { - s->_msgState.loadRes(s->resmgr, argv[1].toUint16(), true); + s->_msgState.loadRes(s->resourceManager, argv[1].toUint16(), true); s->_msgState.findTuple(tuple); if (isGetMessage) @@ -758,7 +758,7 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) { case K_MESSAGE_SIZE: { MessageState tempState; - if (tempState.loadRes(s->resmgr, argv[1].toUint16(), false) && tempState.findTuple(tuple) && tempState.getMessage()) + if (tempState.loadRes(s->resourceManager, argv[1].toUint16(), false) && tempState.findTuple(tuple) && tempState.getMessage()) return make_reg(0, tempState.getText().size() + 1); else return NULL_REG; @@ -768,7 +768,7 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) { case K_MESSAGE_REFNOUN: { MessageState tempState; - if (tempState.loadRes(s->resmgr, argv[1].toUint16(), false) && tempState.findTuple(tuple)) { + if (tempState.loadRes(s->resourceManager, argv[1].toUint16(), false) && tempState.findTuple(tuple)) { MessageTuple t = tempState.getRefTuple(); switch (func) { case K_MESSAGE_REFCOND: diff --git a/engines/sci/engine/memobj.cpp b/engines/sci/engine/memobj.cpp index 34432521a0..7b28bde663 100644 --- a/engines/sci/engine/memobj.cpp +++ b/engines/sci/engine/memobj.cpp @@ -224,12 +224,12 @@ byte *SystemStrings::dereference(reg_t pointer, int *size) { //-------------------- script -------------------- -reg_t Script::findCanonicAddress(SegManager *segmgr, reg_t addr) { +reg_t Script::findCanonicAddress(SegManager *segManager, reg_t addr) { addr.offset = 0; return addr; } -void Script::freeAtAddress(SegManager *segmgr, reg_t addr) { +void Script::freeAtAddress(SegManager *segManager, reg_t addr) { /* debugC(2, kDebugLevelGC, "[GC] Freeing script %04x:%04x\n", PRINT_REG(addr)); if (locals_segment) @@ -237,16 +237,15 @@ void Script::freeAtAddress(SegManager *segmgr, reg_t addr) { */ if (_markedAsDeleted) - segmgr->deallocateScript(nr); + segManager->deallocateScript(nr); } void Script::listAllDeallocatable(SegmentId segId, void *param, NoteCallback note) { (*note)(param, make_reg(segId, 0)); } -void Script::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, NoteCallback note) { +void Script::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note, SciVersion version) { Script *script = this; - SciVersion version = s->_version; // for the offset defines if (addr.offset <= script->buf_size && addr.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET && RAW_IS_OBJECT(script->buf + addr.offset)) { int idx = RAW_GET_CLASS_INDEX(script, addr); @@ -270,7 +269,7 @@ void Script::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, //-------------------- clones -------------------- -void CloneTable::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, NoteCallback note) { +void CloneTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note, SciVersion version) { CloneTable *clone_table = this; Clone *clone; @@ -293,7 +292,7 @@ void CloneTable::listAllOutgoingReferences(EngineState *s, reg_t addr, void *par //debugC(2, kDebugLevelGC, "[GC] Reporting clone-pos %04x:%04x\n", PRINT_REG(clone->pos)); } -void CloneTable::freeAtAddress(SegManager *segmgr, reg_t addr) { +void CloneTable::freeAtAddress(SegManager *segManager, reg_t addr) { CloneTable *clone_table = this; Object *victim_obj; @@ -318,16 +317,16 @@ void CloneTable::freeAtAddress(SegManager *segmgr, reg_t addr) { //-------------------- locals -------------------- -reg_t LocalVariables::findCanonicAddress(SegManager *segmgr, reg_t addr) { +reg_t LocalVariables::findCanonicAddress(SegManager *segManager, reg_t addr) { // Reference the owning script - SegmentId owner_seg = segmgr->segGet(script_id); + SegmentId owner_seg = segManager->segGet(script_id); assert(owner_seg >= 0); return make_reg(owner_seg, 0); } -void LocalVariables::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, NoteCallback note) { +void LocalVariables::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note, SciVersion version) { // assert(addr.segment == _segId); for (uint i = 0; i < _locals.size(); i++) @@ -336,12 +335,12 @@ void LocalVariables::listAllOutgoingReferences(EngineState *s, reg_t addr, void //-------------------- stack -------------------- -reg_t DataStack::findCanonicAddress(SegManager *segmgr, reg_t addr) { +reg_t DataStack::findCanonicAddress(SegManager *segManager, reg_t addr) { addr.offset = 0; return addr; } -void DataStack::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, NoteCallback note) { +void DataStack::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note, SciVersion version) { fprintf(stderr, "Emitting %d stack entries\n", nr); for (int i = 0; i < nr; i++) (*note)(param, entries[i]); @@ -350,11 +349,11 @@ void DataStack::listAllOutgoingReferences(EngineState *s, reg_t addr, void *para //-------------------- lists -------------------- -void ListTable::freeAtAddress(SegManager *segmgr, reg_t sub_addr) { +void ListTable::freeAtAddress(SegManager *segManager, reg_t sub_addr) { freeEntry(sub_addr.offset); } -void ListTable::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, NoteCallback note) { +void ListTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note, SciVersion version) { if (!isValidEntry(addr.offset)) { warning("Invalid list referenced for outgoing references: %04x:%04x", PRINT_REG(addr)); return; @@ -370,11 +369,11 @@ void ListTable::listAllOutgoingReferences(EngineState *s, reg_t addr, void *para //-------------------- nodes -------------------- -void NodeTable::freeAtAddress(SegManager *segmgr, reg_t sub_addr) { +void NodeTable::freeAtAddress(SegManager *segManager, reg_t sub_addr) { freeEntry(sub_addr.offset); } -void NodeTable::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, NoteCallback note) { +void NodeTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note, SciVersion version) { if (!isValidEntry(addr.offset)) { warning("Invalid node referenced for outgoing references: %04x:%04x", PRINT_REG(addr)); return; @@ -394,7 +393,7 @@ void NodeTable::listAllOutgoingReferences(EngineState *s, reg_t addr, void *para //-------------------- dynamic memory -------------------- -reg_t DynMem::findCanonicAddress(SegManager *segmgr, reg_t addr) { +reg_t DynMem::findCanonicAddress(SegManager *segManager, reg_t addr) { addr.offset = 0; return addr; } diff --git a/engines/sci/engine/memobj.h b/engines/sci/engine/memobj.h index efe7f26f1c..52d0b7859e 100644 --- a/engines/sci/engine/memobj.h +++ b/engines/sci/engine/memobj.h @@ -52,7 +52,7 @@ enum MemObjectType { struct MemObject : public Common::Serializable { MemObjectType _type; - int _segmgrId; /**< Internal value used by the seg_manager's hash map */ + int _segManagerId; /**< Internal value used by the segmentManager's hash map */ typedef void (*NoteCallback)(void *param, reg_t addr); // FIXME: Bad choice of name @@ -63,7 +63,7 @@ public: virtual ~MemObject() {} inline MemObjectType getType() const { return _type; } - inline int getSegMgrId() const { return _segmgrId; } + inline int getSegmentManagerId() const { return _segManagerId; } /** * Check whether the given offset into this memory object is valid, @@ -87,13 +87,13 @@ public: * * @param sub_addr base address whose canonic address is to be found */ - virtual reg_t findCanonicAddress(SegManager *segmgr, reg_t sub_addr) { return sub_addr; } + virtual reg_t findCanonicAddress(SegManager *segManager, reg_t sub_addr) { return sub_addr; } /** * Deallocates all memory associated with the specified address. * @param sub_addr address (within the given segment) to deallocate */ - virtual void freeAtAddress(SegManager *segmgr, reg_t sub_addr) {} + virtual void freeAtAddress(SegManager *segManager, reg_t sub_addr) {} /** * Iterates over and reports all addresses within the current segment. @@ -109,7 +109,7 @@ public: * @param note Invoked for each outgoing reference within the object * Note: This function may also choose to report numbers (segment 0) as adresses */ - virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note) {} + virtual void listAllOutgoingReferences(reg_t object, void *param, NoteCallback note, SciVersion version) {} }; @@ -191,8 +191,8 @@ public: virtual bool isValidOffset(uint16 offset) const; virtual byte *dereference(reg_t pointer, int *size); - virtual reg_t findCanonicAddress(SegManager *segmgr, reg_t sub_addr); - virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note); + virtual reg_t findCanonicAddress(SegManager *segManager, reg_t sub_addr); + virtual void listAllOutgoingReferences(reg_t object, void *param, NoteCallback note, SciVersion version); virtual void saveLoadWithSerializer(Common::Serializer &ser); }; @@ -218,16 +218,16 @@ struct CodeBlock { }; #define VM_OBJECT_GET_VARSELECTOR(obj, i) \ - (s->_version < SCI_VERSION_1_1 ? \ + (version < SCI_VERSION_1_1 ? \ READ_LE_UINT16(obj->base_obj + obj->_variables.size() * 2 + i*2) : \ *(obj->base_vars + i)) #define VM_OBJECT_READ_PROPERTY(obj, i) (obj->_variables[i]) #define VM_OBJECT_GET_FUNCSELECTOR(obj, i) \ - (s->_version < SCI_VERSION_1_1 ? \ + (version < SCI_VERSION_1_1 ? \ READ_LE_UINT16((byte *) (obj->base_method + i)) : \ READ_LE_UINT16((byte *) (obj->base_method + i*2 + 1))) #define VM_OBJECT_READ_FUNCTION(obj, i) \ - (s->_version < SCI_VERSION_1_1 ? \ + (version < SCI_VERSION_1_1 ? \ make_reg(obj->pos.segment, \ READ_LE_UINT16((byte *) (obj->base_method \ + obj->methods_nr + 1 \ @@ -301,10 +301,10 @@ public: virtual bool isValidOffset(uint16 offset) const; virtual byte *dereference(reg_t pointer, int *size); - virtual reg_t findCanonicAddress(SegManager *segmgr, reg_t sub_addr); - virtual void freeAtAddress(SegManager *segmgr, reg_t sub_addr); + virtual reg_t findCanonicAddress(SegManager *segManager, reg_t sub_addr); + virtual void freeAtAddress(SegManager *segManager, reg_t sub_addr); virtual void listAllDeallocatable(SegmentId segId, void *param, NoteCallback note); - virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note); + virtual void listAllOutgoingReferences(reg_t object, void *param, NoteCallback note, SciVersion version); virtual void saveLoadWithSerializer(Common::Serializer &ser); @@ -416,8 +416,8 @@ public: virtual bool isValidOffset(uint16 offset) const; virtual byte *dereference(reg_t pointer, int *size); - virtual reg_t findCanonicAddress(SegManager *segmgr, reg_t sub_addr); - virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note); + virtual reg_t findCanonicAddress(SegManager *segManager, reg_t sub_addr); + virtual void listAllOutgoingReferences(reg_t object, void *param, NoteCallback note, SciVersion version); virtual void saveLoadWithSerializer(Common::Serializer &ser); }; @@ -513,8 +513,8 @@ public: /* CloneTable */ struct CloneTable : public Table<Clone> { - virtual void freeAtAddress(SegManager *segmgr, reg_t sub_addr); - virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note); + virtual void freeAtAddress(SegManager *segManager, reg_t sub_addr); + virtual void listAllOutgoingReferences(reg_t object, void *param, NoteCallback note, SciVersion version); virtual void saveLoadWithSerializer(Common::Serializer &ser); }; @@ -522,8 +522,8 @@ struct CloneTable : public Table<Clone> { /* NodeTable */ struct NodeTable : public Table<Node> { - virtual void freeAtAddress(SegManager *segmgr, reg_t sub_addr); - virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note); + virtual void freeAtAddress(SegManager *segManager, reg_t sub_addr); + virtual void listAllOutgoingReferences(reg_t object, void *param, NoteCallback note, SciVersion version); virtual void saveLoadWithSerializer(Common::Serializer &ser); }; @@ -531,8 +531,8 @@ struct NodeTable : public Table<Node> { /* ListTable */ struct ListTable : public Table<List> { - virtual void freeAtAddress(SegManager *segmgr, reg_t sub_addr); - virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note); + virtual void freeAtAddress(SegManager *segManager, reg_t sub_addr); + virtual void listAllOutgoingReferences(reg_t object, void *param, NoteCallback note, SciVersion version); virtual void saveLoadWithSerializer(Common::Serializer &ser); }; @@ -567,7 +567,7 @@ public: virtual bool isValidOffset(uint16 offset) const; virtual byte *dereference(reg_t pointer, int *size); - virtual reg_t findCanonicAddress(SegManager *segmgr, reg_t sub_addr); + virtual reg_t findCanonicAddress(SegManager *segManager, reg_t sub_addr); virtual void listAllDeallocatable(SegmentId segId, void *param, NoteCallback note); virtual void saveLoadWithSerializer(Common::Serializer &ser); diff --git a/engines/sci/engine/message.cpp b/engines/sci/engine/message.cpp index a55d692afe..fe122e960f 100644 --- a/engines/sci/engine/message.cpp +++ b/engines/sci/engine/message.cpp @@ -220,7 +220,7 @@ int MessageState::getLength() { return strlen(stringptr); } -int MessageState::loadRes(ResourceManager *resmgr, int module, bool lock) { +int MessageState::loadRes(ResourceManager *resourceManager, int module, bool lock) { if (_locked) { // We already have a locked resource if (_module == module) { @@ -229,11 +229,11 @@ int MessageState::loadRes(ResourceManager *resmgr, int module, bool lock) { } // Otherwise, free the old resource - resmgr->unlockResource(_currentResource); + resourceManager->unlockResource(_currentResource); _locked = false; } - _currentResource = resmgr->findResource(ResourceId(kResourceTypeMessage, module), lock); + _currentResource = resourceManager->findResource(ResourceId(kResourceTypeMessage, module), lock); if (_currentResource == NULL || _currentResource->data == NULL) { warning("Message: failed to load %d.msg", module); diff --git a/engines/sci/engine/message.h b/engines/sci/engine/message.h index 5e30095a0c..5a9dab6684 100644 --- a/engines/sci/engine/message.h +++ b/engines/sci/engine/message.h @@ -59,7 +59,7 @@ public: int getLength(); MessageTuple &getLastTuple(); int getLastModule(); - int loadRes(ResourceManager *resmgr, int module, bool lock); + int loadRes(ResourceManager *resourceManager, int module, bool lock); private: void initCursor(); diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index b53e9d522c..2e06afa3cd 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -205,13 +205,11 @@ void SegManager::saveLoadWithSerializer(Common::Serializer &s) { } static void sync_SegManagerPtr(Common::Serializer &s, SegManager *&obj) { - SciVersion version = SCI_VERSION_AUTODETECT; - ResourceManager *resMgr = 0; + ResourceManager *resourceManager = 0; if (s.isSaving()) { assert(obj); - version = obj->_version; - resMgr = obj->_resMgr; + resourceManager = obj->_resourceManager; } s.skip(1); // obsolete: used to be a flag indicating if we got sci11 or not @@ -219,7 +217,7 @@ static void sync_SegManagerPtr(Common::Serializer &s, SegManager *&obj) { if (s.isLoading()) { // FIXME: Do in-place loading at some point, instead of creating a new EngineState instance from scratch. delete obj; - obj = new SegManager(resMgr, version); + obj = new SegManager(resourceManager); } obj->saveLoadWithSerializer(s); @@ -244,7 +242,7 @@ static void sync_SavegameMetadata(Common::Serializer &s, SavegameMetadata &obj) s.syncString(obj.savegame_name); s.syncAsSint32LE(obj.savegame_version); s.syncString(obj.game_version); - s.syncAsSint32LE(obj.version); + s.skip(4); // obsolete: used to be game version s.syncAsSint32LE(obj.savegame_date); s.syncAsSint32LE(obj.savegame_time); } @@ -266,9 +264,9 @@ void EngineState::saveLoadWithSerializer(Common::Serializer &s) { s.syncAsSint32LE(status_bar_foreground); s.syncAsSint32LE(status_bar_background); - sync_SegManagerPtr(s, seg_manager); + sync_SegManagerPtr(s, segmentManager); - syncArray<Class>(s, seg_manager->_classtable); + syncArray<Class>(s, segmentManager->_classtable); sync_sfx_state_t(s, _sound); } @@ -445,7 +443,7 @@ static void sync_MemObjPtr(Common::Serializer &s, MemObject *&mobj) { assert(mobj); } - s.syncAsSint32LE(mobj->_segmgrId); + s.syncAsSint32LE(mobj->_segManagerId); mobj->saveLoadWithSerializer(s); } @@ -460,7 +458,6 @@ int gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savename SavegameMetadata meta; meta.savegame_version = CURRENT_SAVEGAME_VERSION; meta.savegame_name = savename; - meta.version = s->_version; meta.game_version = s->game_version; meta.savegame_date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF); meta.savegame_time = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF); @@ -499,7 +496,9 @@ static SegmentId find_unique_seg_by_type(SegManager *self, int type) { } static byte *find_unique_script_block(EngineState *s, byte *buf, int type) { - if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) + bool oldScriptHeader = (s->resourceManager->sciVersion() == SCI_VERSION_0_EARLY); + + if (oldScriptHeader) buf += 2; do { @@ -518,8 +517,8 @@ static byte *find_unique_script_block(EngineState *s, byte *buf, int type) { // FIXME: This should probably be turned into an EngineState method static void reconstruct_stack(EngineState *retval) { - SegmentId stack_seg = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_STACK); - DataStack *stack = (DataStack *)(retval->seg_manager->_heap[stack_seg]); + SegmentId stack_seg = find_unique_seg_by_type(retval->segmentManager, MEM_OBJ_STACK); + DataStack *stack = (DataStack *)(retval->segmentManager->_heap[stack_seg]); retval->stack_segment = stack_seg; retval->stack_base = stack->entries; @@ -540,18 +539,18 @@ static bool clone_entry_used(CloneTable *table, int n) { static void load_script(EngineState *s, SegmentId seg) { Resource *script, *heap = NULL; - Script *scr = (Script *)(s->seg_manager->_heap[seg]); + Script *scr = (Script *)(s->segmentManager->_heap[seg]); assert(scr); scr->buf = (byte *)malloc(scr->buf_size); assert(scr->buf); - script = s->resmgr->findResource(ResourceId(kResourceTypeScript, scr->nr), 0); - if (s->_version >= SCI_VERSION_1_1) - heap = s->resmgr->findResource(ResourceId(kResourceTypeHeap, scr->nr), 0); + script = s->resourceManager->findResource(ResourceId(kResourceTypeScript, scr->nr), 0); + if (s->resourceManager->sciVersion() >= SCI_VERSION_1_1) + heap = s->resourceManager->findResource(ResourceId(kResourceTypeHeap, scr->nr), 0); memcpy(scr->buf, script->data, script->size); - if (s->seg_manager->_version == SCI_VERSION_1_1) + if (s->resourceManager->sciVersion() == SCI_VERSION_1_1) memcpy(scr->buf + scr->script_size, heap->data, heap->size); } @@ -559,7 +558,7 @@ static void load_script(EngineState *s, SegmentId seg) { static void reconstruct_scripts(EngineState *s, SegManager *self) { uint i, j; MemObject *mobj; - SciVersion version = s->_version; // for the selector defines + SciVersion version = self->sciVersion(); // for the selector defines for (i = 0; i < self->_heap.size(); i++) { if (self->_heap[i]) { @@ -570,8 +569,8 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { // FIXME: Unify this code with script_instantiate_* load_script(s, i); - scr->locals_block = (scr->locals_segment == 0) ? NULL : (LocalVariables *)(s->seg_manager->_heap[scr->locals_segment]); - if (s->seg_manager->_version == SCI_VERSION_1_1) { + scr->locals_block = (scr->locals_segment == 0) ? NULL : (LocalVariables *)(s->segmentManager->_heap[scr->locals_segment]); + if (s->resourceManager->sciVersion() == SCI_VERSION_1_1) { scr->export_table = 0; scr->synonyms = 0; if (READ_LE_UINT16(scr->buf + 6) > 0) { @@ -607,7 +606,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { for (j = 0; j < scr->_objects.size(); j++) { byte *data = scr->buf + scr->_objects[j].pos.offset; - if (self->_version == SCI_VERSION_1_1) { + if (s->resourceManager->sciVersion() == SCI_VERSION_1_1) { uint16 *funct_area = (uint16 *) (scr->buf + READ_LE_UINT16( data + 6 )); uint16 *prop_area = (uint16 *) (scr->buf + READ_LE_UINT16( data + 4 )); @@ -617,7 +616,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { int funct_area = READ_LE_UINT16( data + SCRIPT_FUNCTAREAPTR_OFFSET ); Object *base_obj; - base_obj = obj_get(s->seg_manager, s->_version, scr->_objects[j]._variables[SCRIPT_SPECIES_SELECTOR]); + base_obj = obj_get(s->segmentManager, scr->_objects[j]._variables[SCRIPT_SPECIES_SELECTOR]); if (!base_obj) { warning("Object without a base class: Script %d, index %d (reg address %04x:%04x", @@ -641,8 +640,8 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { } // FIXME: The following should likely become a SegManager method -static void reconstruct_clones(EngineState *s, SegManager *self) { - SciVersion version = s->_version; // for the selector defines +static void reconstruct_clones(SegManager *self) { + SciVersion version = self->sciVersion(); // for the selector defines for (uint i = 0; i < self->_heap.size(); i++) { if (self->_heap[i]) { @@ -673,7 +672,7 @@ static void reconstruct_clones(EngineState *s, SegManager *self) { continue; } CloneTable::Entry &seeker = ct->_table[j]; - base_obj = obj_get(s->seg_manager, s->_version, seeker._variables[SCRIPT_SPECIES_SELECTOR]); + base_obj = obj_get(self, seeker._variables[SCRIPT_SPECIES_SELECTOR]); if (!base_obj) { printf("Clone entry without a base class: %d\n", j); seeker.base = seeker.base_obj = NULL; @@ -701,7 +700,7 @@ static void reconstruct_sounds(EngineState *s) { Song *seeker; SongIteratorType it_type; - if (s->_version > SCI_VERSION_01) + if (s->resourceManager->sciVersion() > SCI_VERSION_01) it_type = SCI_SONG_ITERATOR_TYPE_SCI1; else it_type = SCI_SONG_ITERATOR_TYPE_SCI0; @@ -765,7 +764,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { } // FIXME: Do in-place loading at some point, instead of creating a new EngineState instance from scratch. - retval = new EngineState(s->resmgr, s->_version, s->_flags); + retval = new EngineState(s->resourceManager, s->_flags); // Copy some old data retval->gfx_state = s->gfx_state; @@ -786,20 +785,20 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { retval->old_screen = 0; temp = retval->_sound._songlib; - retval->_sound.sfx_init(retval->resmgr, s->sfx_init_flags); + retval->_sound.sfx_init(retval->resourceManager, s->sfx_init_flags); retval->sfx_init_flags = s->sfx_init_flags; retval->_sound._songlib.freeSounds(); retval->_sound._songlib = temp; _reset_graphics_input(retval); reconstruct_stack(retval); - reconstruct_scripts(retval, retval->seg_manager); - reconstruct_clones(retval, retval->seg_manager); + reconstruct_scripts(retval, retval->segmentManager); + reconstruct_clones(retval->segmentManager); retval->game_obj = s->game_obj; - retval->script_000 = retval->seg_manager->getScript(retval->seg_manager->getSegment(0, SCRIPT_GET_DONT_LOAD)); + retval->script_000 = retval->segmentManager->getScript(retval->segmentManager->getSegment(0, SCRIPT_GET_DONT_LOAD)); retval->gc_countdown = GC_INTERVAL - 1; - retval->sys_strings_segment = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_SYS_STRINGS); - retval->sys_strings = (SystemStrings *)GET_SEGMENT(*retval->seg_manager, retval->sys_strings_segment, MEM_OBJ_SYS_STRINGS); + retval->sys_strings_segment = find_unique_seg_by_type(retval->segmentManager, MEM_OBJ_SYS_STRINGS); + retval->sys_strings = (SystemStrings *)GET_SEGMENT(*retval->segmentManager, retval->sys_strings_segment, MEM_OBJ_SYS_STRINGS); // Restore system strings SystemString *str; @@ -836,7 +835,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { retval->successor = NULL; retval->pic_priority_table = (int *)gfxop_get_pic_metainfo(retval->gfx_state); - retval->_gameName = obj_get_name(retval->seg_manager, retval->_version, retval->game_obj); + retval->_gameName = obj_get_name(retval->segmentManager, retval->game_obj); retval->_sound._it = NULL; retval->_sound._flags = s->_sound._flags; diff --git a/engines/sci/engine/savegame.h b/engines/sci/engine/savegame.h index f53dbb4956..b238b7730a 100644 --- a/engines/sci/engine/savegame.h +++ b/engines/sci/engine/savegame.h @@ -40,7 +40,6 @@ struct SavegameMetadata { Common::String savegame_name; int savegame_version; Common::String game_version; - sci_version_t version; int savegame_date; int savegame_time; }; diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index 6e47a73b18..12d721ecc5 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -285,7 +285,7 @@ void Kernel::dumpScriptClass(char *data, int seeker, int objsize) { void Kernel::dissectScript(int scriptNumber, Vocabulary *vocab) { int objectctr[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; unsigned int _seeker = 0; - Resource *script = _resmgr->findResource(ResourceId(kResourceTypeScript, scriptNumber), 0); + Resource *script = _resourceManager->findResource(ResourceId(kResourceTypeScript, scriptNumber), 0); if (!script) { warning("dissectScript(): Script not found!\n"); diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index fd7219bc85..28e22cb56e 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -36,11 +36,11 @@ extern const char *selector_name(EngineState *s, int selector); ScriptState scriptState; -int propertyOffsetToId(EngineState *s, int prop_ofs, reg_t objp) { - Object *obj = obj_get(s->seg_manager, s->_version, objp); +int propertyOffsetToId(SegManager *segManager, int prop_ofs, reg_t objp) { + Object *obj = obj_get(segManager, objp); byte *selectoroffset; int selectors; - SciVersion version = s->_version; // for the selector defines + SciVersion version = segManager->sciVersion(); // for the selector defines if (!obj) { warning("Applied propertyOffsetToId on non-object at %04x:%04x", PRINT_REG(objp)); @@ -49,11 +49,11 @@ int propertyOffsetToId(EngineState *s, int prop_ofs, reg_t objp) { selectors = obj->_variables.size(); - if (s->_version < SCI_VERSION_1_1) + if (segManager->sciVersion() < SCI_VERSION_1_1) selectoroffset = ((byte *)(obj->base_obj)) + SCRIPT_SELECTOR_OFFSET + selectors * 2; else { if (!(obj->_variables[SCRIPT_INFO_SELECTOR].offset & SCRIPT_INFO_CLASS)) { - obj = obj_get(s->seg_manager, s->_version, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR]); + obj = obj_get(segManager, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR]); selectoroffset = (byte *)obj->base_vars; } else selectoroffset = (byte *)obj->base_vars; @@ -70,7 +70,7 @@ int propertyOffsetToId(EngineState *s, int prop_ofs, reg_t objp) { reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecode) { // Disassembles one command from the heap, returns address of next command or 0 if a ret was encountered. - MemObject *mobj = GET_SEGMENT(*s->seg_manager, pos.segment, MEM_OBJ_SCRIPT); + MemObject *mobj = GET_SEGMENT(*s->segmentManager, pos.segment, MEM_OBJ_SCRIPT); Script *script_entity = NULL; byte *scr; int scr_size; @@ -226,7 +226,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod if ((opcode == op_pTos) || (opcode == op_sTop) || (opcode == op_pToa) || (opcode == op_aTop) || (opcode == op_dpToa) || (opcode == op_ipToa) || (opcode == op_dpTos) || (opcode == op_ipTos)) { int prop_ofs = scr[pos.offset + 1]; - int prop_id = propertyOffsetToId(s, prop_ofs, scriptState.xs->objp); + int prop_id = propertyOffsetToId(s->segmentManager, prop_ofs, scriptState.xs->objp); printf(" (%s)", selector_name(s, prop_id)); } @@ -238,8 +238,9 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod if (opcode == op_callk) { int stackframe = (scr[pos.offset + 2] >> 1) + (scriptState.restAdjust); int argc = ((scriptState.xs->sp)[- stackframe - 1]).offset; + bool oldScriptHeader = (s->segmentManager->sciVersion() == SCI_VERSION_0_EARLY); - if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) + if (!oldScriptHeader) argc += (scriptState.restAdjust); printf(" Kernel params: ("); @@ -269,14 +270,14 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod selector = sb[- stackframe].offset; - name = obj_get_name(s->seg_manager, s->_version, called_obj_addr); + name = obj_get_name(s->segmentManager, called_obj_addr); if (!name) name = "<invalid>"; printf(" %s::%s[", name, (selector > ((SciEngine*)g_engine)->getKernel()->getSelectorNamesSize()) ? "<invalid>" : selector_name(s, selector)); - switch (lookup_selector(s, called_obj_addr, selector, 0, &fun_ref)) { + switch (lookup_selector(s->segmentManager, called_obj_addr, selector, 0, &fun_ref)) { case kSelectorMethod: printf("FUNCT"); argc += restmod; @@ -328,7 +329,7 @@ void script_debug(EngineState *s, bool bp) { #endif if (scriptState.seeking && !bp) { // Are we looking for something special? - MemObject *mobj = GET_SEGMENT(*s->seg_manager, scriptState.xs->addr.pc.segment, MEM_OBJ_SCRIPT); + MemObject *mobj = GET_SEGMENT(*s->segmentManager, scriptState.xs->addr.pc.segment, MEM_OBJ_SCRIPT); if (mobj) { Script *scr = (Script *)mobj; diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 0c88481125..53b4b039a3 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -48,11 +48,11 @@ namespace Sci { //#define GC_DEBUG // Debug garbage collection //#define GC_DEBUG_VERBOSE // Debug garbage verbosely -#undef DEBUG_SEG_MANAGER // Define to turn on debugging +#undef DEBUG_segmentManager // Define to turn on debugging #define INVALID_SCRIPT_ID -1 -SegManager::SegManager(ResourceManager *resMgr, SciVersion version) { +SegManager::SegManager(ResourceManager *resourceManager) { id_seg_map = new IntMapper(); reserved_id = INVALID_SCRIPT_ID; id_seg_map->checkKey(reserved_id, true); // reserve entry 0 for INVALID_SCRIPT_ID @@ -66,8 +66,7 @@ SegManager::SegManager(ResourceManager *resMgr, SciVersion version) { Hunks_seg_id = 0; exports_wide = 0; - _version = version; - _resMgr = resMgr; + _resourceManager = resourceManager; int result = 0; @@ -137,19 +136,19 @@ Script *SegManager::allocateScript(int script_nr, SegmentId *seg_id) { } void SegManager::setScriptSize(Script &scr, int script_nr) { - Resource *script = _resMgr->findResource(ResourceId(kResourceTypeScript, script_nr), 0); - Resource *heap = _resMgr->findResource(ResourceId(kResourceTypeHeap, script_nr), 0); + Resource *script = _resourceManager->findResource(ResourceId(kResourceTypeScript, script_nr), 0); + Resource *heap = _resourceManager->findResource(ResourceId(kResourceTypeHeap, script_nr), 0); scr.script_size = script->size; scr.heap_size = 0; // Set later - if (!script || (_version >= SCI_VERSION_1_1 && !heap)) { + if (!script || (_resourceManager->sciVersion() >= SCI_VERSION_1_1 && !heap)) { error("SegManager::setScriptSize: failed to load %s", !script ? "script" : "heap"); } - if (_version == SCI_VERSION_0_EARLY) { // check if we got an old script header + if (_resourceManager->sciVersion() == SCI_VERSION_0_EARLY) { // check if we got an old script header scr.buf_size = script->size + READ_LE_UINT16(script->data) * 2; //locals_size = READ_LE_UINT16(script->data) * 2; - } else if (_version < SCI_VERSION_1_1) { + } else if (_resourceManager->sciVersion() < SCI_VERSION_1_1) { scr.buf_size = script->size; } else { scr.buf_size = script->size + heap->size; @@ -177,7 +176,7 @@ int SegManager::initialiseScript(Script &scr, int script_nr) { setScriptSize(scr, script_nr); scr.buf = (byte *)malloc(scr.buf_size); -#ifdef DEBUG_SEG_MANAGER +#ifdef DEBUG_segmentManager printf("scr.buf = %p ", scr.buf); #endif if (!scr.buf) { @@ -199,7 +198,7 @@ int SegManager::initialiseScript(Script &scr, int script_nr) { scr.obj_indices = new IntMapper(); - if (_version >= SCI_VERSION_1_1) + if (_resourceManager->sciVersion() >= SCI_VERSION_1_1) scr.heap_start = scr.buf + scr.script_size; else scr.heap_start = scr.buf; @@ -212,7 +211,7 @@ int SegManager::deallocate(SegmentId seg, bool recursive) { VERIFY(check(seg), "invalid seg id"); mobj = _heap[seg]; - id_seg_map->removeKey(mobj->getSegMgrId()); + id_seg_map->removeKey(mobj->getSegmentManagerId()); if (mobj->getType() == MEM_OBJ_SCRIPT) { Script *scr = (Script *)mobj; @@ -254,7 +253,7 @@ MemObject *SegManager::memObjAllocate(SegmentId segid, int hash_id, MemObjectTyp _heap.push_back(0); } - mem->_segmgrId = hash_id; + mem->_segManagerId = hash_id; // hook it to the heap _heap[segid] = mem; @@ -327,7 +326,7 @@ int SegManager::relocateBlock(Common::Array<reg_t> &block, int block_location, S return 0; } block[idx].segment = segment; // Perform relocation - if (_version == SCI_VERSION_1_1) + if (_resourceManager->sciVersion() == SCI_VERSION_1_1) block[idx].offset += getScript(segment)->script_size; return 1; @@ -441,7 +440,7 @@ SegmentId SegManager::getSegment(int script_nr, SCRIPT_GET load) { SegmentId segment; if ((load & SCRIPT_GET_LOAD) == SCRIPT_GET_LOAD) - script_instantiate(_resMgr, this, _version, script_nr); + script_instantiate(_resourceManager, this, script_nr); segment = segGet(script_nr); @@ -481,7 +480,7 @@ reg_t SegManager::get_class_address(int classnr, SCRIPT_GET lock, reg_t caller) Object *SegManager::scriptObjInit0(reg_t obj_pos) { Object *obj; int id; - SciVersion version = _version; // for the offset defines + SciVersion version = _resourceManager->sciVersion(); // for the offset defines unsigned int base = obj_pos.offset - SCRIPT_OBJECT_MAGIC_OFFSET; reg_t temp; @@ -590,7 +589,7 @@ Object *SegManager::scriptObjInit11(reg_t obj_pos) { } Object *SegManager::scriptObjInit(reg_t obj_pos) { - if (_version != SCI_VERSION_1_1) + if (_resourceManager->sciVersion() != SCI_VERSION_1_1) return scriptObjInit0(obj_pos); else return scriptObjInit11(obj_pos); @@ -634,7 +633,7 @@ void SegManager::scriptInitialiseLocals(reg_t location) { VERIFY(location.offset + 1 < (uint16)scr->buf_size, "Locals beyond end of script\n"); - if (_version == SCI_VERSION_1_1) + if (_resourceManager->sciVersion() == SCI_VERSION_1_1) count = READ_LE_UINT16(scr->buf + location.offset - 2); else count = (READ_LE_UINT16(scr->buf + location.offset - 2) - 4) >> 1; @@ -676,7 +675,7 @@ void SegManager::scriptRelocateExportsSci11(SegmentId seg) { void SegManager::scriptInitialiseObjectsSci11(SegmentId seg) { Script *scr = getScript(seg); byte *seeker = scr->heap_start + 4 + READ_LE_UINT16(scr->heap_start + 2) * 2; - SciVersion version = _version; // for the selector defines + SciVersion version = _resourceManager->sciVersion(); // for the selector defines while (READ_LE_UINT16(seeker) == SCRIPT_OBJECT_MAGIC_NUMBER) { if (READ_LE_UINT16(seeker + 14) & SCRIPT_INFO_CLASS) { @@ -707,7 +706,7 @@ void SegManager::scriptInitialiseObjectsSci11(SegmentId seg) { #if 0 if (obj->_variables[5].offset != 0xffff) { obj->_variables[5] = INST_LOOKUP_CLASS(obj->_variables[5].offset); - base_obj = obj_get(s->seg_manager, s->_version, obj->_variables[5]); + base_obj = obj_get(s->segmentManager, obj->_variables[5]); obj->variable_names_nr = base_obj->variables_nr; obj->base_obj = base_obj->base_obj; } @@ -913,7 +912,7 @@ int SegManager::freeDynmem(reg_t addr) { } int SegManager::createClassTable() { - Resource *vocab996 = _resMgr->findResource(ResourceId(kResourceTypeVocab, 996), 1); + Resource *vocab996 = _resourceManager->findResource(ResourceId(kResourceTypeVocab, 996), 1); if (!vocab996) error("SegManager: failed to open vocab 996"); @@ -928,7 +927,7 @@ int SegManager::createClassTable() { _classtable[classNr].script = scriptNr; } - _resMgr->unlockResource(vocab996); + _resourceManager->unlockResource(vocab996); return 0; } diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h index 27c8ad446a..57a7bbe447 100644 --- a/engines/sci/engine/seg_manager.h +++ b/engines/sci/engine/seg_manager.h @@ -23,8 +23,8 @@ * */ -#ifndef SCI_ENGINE_SEG_MANAGER_H -#define SCI_ENGINE_SEG_MANAGER_H +#ifndef SCI_ENGINE_segmentManager_H +#define SCI_ENGINE_segmentManager_H #include "common/scummsys.h" #include "common/serializer.h" @@ -58,7 +58,7 @@ public: /** * Initialize the segment manager */ - SegManager(ResourceManager *resMgr, SciVersion version); + SegManager(ResourceManager *resourceManager); /** * Deallocate all memory associated with the segment manager @@ -340,15 +340,16 @@ public: void scriptInitialiseObjectsSci11(SegmentId seg); int initialiseScript(Script &scr, int script_nr); + SciVersion sciVersion() { return _resourceManager->sciVersion(); } + private: IntMapper *id_seg_map; ///< id - script id; seg - index of heap public: // TODO: make private Common::Array<MemObject *> _heap; int reserved_id; int exports_wide; - SciVersion _version; - ResourceManager *_resMgr; Common::Array<Class> _classtable; /**< Table of all classes */ + ResourceManager *_resourceManager; SegmentId Clones_seg_id; ///< ID of the (a) clones segment SegmentId Lists_seg_id; ///< ID of the (a) list segment @@ -384,4 +385,4 @@ private: } // End of namespace Sci -#endif // SCI_ENGINE_SEG_MANAGER +#endif // SCI_ENGINE_segmentManager diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp index baa51bcb58..c9ba939a4c 100644 --- a/engines/sci/engine/state.cpp +++ b/engines/sci/engine/state.cpp @@ -29,8 +29,8 @@ namespace Sci { -EngineState::EngineState(ResourceManager *res, SciVersion version, uint32 flags) -: resmgr(res), _version(version), _flags(flags), _dirseeker(this) { +EngineState::EngineState(ResourceManager *res, uint32 flags) +: resourceManager(res), _flags(flags), _dirseeker(this) { widget_serial_counter = 0; game_version = 0; @@ -112,12 +112,12 @@ EngineState::EngineState(ResourceManager *res, SciVersion version, uint32 flags) game_obj = NULL_REG; - seg_manager = 0; + segmentManager = 0; gc_countdown = 0; successor = 0; - speedThrottler = new SpeedThrottler(version); + speedThrottler = new SpeedThrottler(res->sciVersion()); _doSoundType = kDoSoundTypeUnknown; } @@ -187,7 +187,7 @@ kLanguage EngineState::getLanguage() { lang = (kLanguage)GET_SEL32V(s->game_obj, printLang); - if ((_version == SCI_VERSION_1_1) || (lang == K_LANG_NONE)) { + if ((s->resourceManager->sciVersion() == SCI_VERSION_1_1) || (lang == K_LANG_NONE)) { // If language is set to none, we use the language from the game detector. // SSCI reads this from resource.cfg (early games do not have a language // setting in resource.cfg, but instead have the secondary language number @@ -254,11 +254,11 @@ EngineState::DoSoundType EngineState::detectDoSoundType() { if (!parse_reg_t(this, "?Sound", &soundClass)) { reg_t fptr; - Object *obj = obj_get(seg_manager, _version, soundClass); - SelectorType sel = lookup_selector(this, soundClass, ((SciEngine*)g_engine)->getKernel()->_selectorMap.play, NULL, &fptr); + Object *obj = obj_get(segmentManager, soundClass); + SelectorType sel = lookup_selector(this->segmentManager, soundClass, ((SciEngine*)g_engine)->getKernel()->_selectorMap.play, NULL, &fptr); if (obj && (sel == kSelectorMethod)) { - Script *script = seg_manager->getScript(fptr.segment); + Script *script = segmentManager->getScript(fptr.segment); if (fptr.offset > checkBytes) { // Go to the last portion of Sound::init, should be right before the play function @@ -289,9 +289,9 @@ EngineState::DoSoundType EngineState::detectDoSoundType() { if (_doSoundType == kDoSoundTypeUnknown) { warning("DoSound detection failed, taking an educated guess"); - if (_version >= SCI_VERSION_1_MIDDLE) + if (resourceManager->sciVersion() >= SCI_VERSION_1_MIDDLE) _doSoundType = kDoSoundTypeSci1Late; - else if (_version > SCI_VERSION_01) + else if (resourceManager->sciVersion() > SCI_VERSION_01) _doSoundType = kDoSoundTypeSci1Early; else _doSoundType = kDoSoundTypeSci0; diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h index a3983f6ae4..50a7a4c5ae 100644 --- a/engines/sci/engine/state.h +++ b/engines/sci/engine/state.h @@ -161,7 +161,7 @@ private: struct EngineState : public Common::Serializable { public: - EngineState(ResourceManager *res, SciVersion version, uint32 flags); + EngineState(ResourceManager *res, uint32 flags); virtual ~EngineState(); enum DoSoundType { @@ -177,9 +177,8 @@ public: public: int widget_serial_counter; /**< Used for savegames */ - ResourceManager *resmgr; /**< The resource manager */ + ResourceManager *resourceManager; /**< The resource manager */ - const SciVersion _version; /**< The approximated patchlevel of the version to emulate */ const uint32 _flags; /**< Specific game flags */ Common::String _gameName; /**< Designation of the primary object (which inherits from Game) */ @@ -305,7 +304,7 @@ public: reg_t game_obj; /**< Pointer to the game object */ - SegManager *seg_manager; + SegManager *segmentManager; int gc_countdown; /**< Number of kernel calls until next gc */ MessageState _msgState; diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index fbdb3d1c85..67b15cd212 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -204,15 +204,15 @@ static void validate_write_var(reg_t *r, reg_t *stack_base, int type, int max, i #define GET_OP_SIGNED_FLEX() ((opcode & 1)? GET_OP_SIGNED_BYTE() : GET_OP_SIGNED_WORD()) ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackPtr sp, reg_t calling_obj, uint16 argc, StackPtr argp) { - int seg = s->seg_manager->segGet(script); - Script *scr = s->seg_manager->getScriptIfLoaded(seg); + int seg = s->segmentManager->segGet(script); + Script *scr = s->segmentManager->getScriptIfLoaded(seg); if (!scr) // Script not present yet? - seg = script_instantiate(s->resmgr, s->seg_manager, s->_version, script); + seg = script_instantiate(s->resourceManager, s->segmentManager, script); else scr->unmarkDeleted(); - int temp = s->seg_manager->validateExportFunc(pubfunct, seg); + int temp = s->segmentManager->validateExportFunc(pubfunct, seg); if (!temp) { error("Request for invalid exported function 0x%x of script 0x%x", pubfunct, script); return NULL; @@ -285,7 +285,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt Breakpoint *bp; char method_name [256]; - sprintf(method_name, "%s::%s", obj_get_name(s->seg_manager, s->_version, send_obj), ((SciEngine*)g_engine)->getKernel()->getSelectorName(selector).c_str()); + sprintf(method_name, "%s::%s", obj_get_name(s->segmentManager, send_obj), ((SciEngine*)g_engine)->getKernel()->getSelectorName(selector).c_str()); bp = s->bp_list; while (bp) { @@ -310,7 +310,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt #endif // VM_DEBUG_SEND ObjVarRef varp; - switch (lookup_selector(s, send_obj, selector, &varp, &funcp)) { + switch (lookup_selector(s->segmentManager, send_obj, selector, &varp, &funcp)) { case kSelectorNone: error("Send to invalid selector 0x%x of object at %04x:%04x", 0xffff & selector, PRINT_REG(send_obj)); @@ -467,7 +467,7 @@ void vm_handle_fatal_error(EngineState *s, int line, const char *file) { } static reg_t pointer_add(EngineState *s, reg_t base, int offset) { - MemObject *mobj = GET_SEGMENT_ANY(*s->seg_manager, base.segment); + MemObject *mobj = GET_SEGMENT_ANY(*s->segmentManager, base.segment); if (!mobj) { error("[VM] Error: Attempt to add %d to invalid pointer %04x:%04x", offset, PRINT_REG(base)); @@ -520,8 +520,8 @@ void run_vm(EngineState *s, int restoring) { // Current execution data: scriptState.xs = &(s->_executionStack.back()); ExecStack *xs_new = NULL; - Object *obj = obj_get(s->seg_manager, s->_version, scriptState.xs->objp); - Script *local_script = s->seg_manager->getScriptIfLoaded(scriptState.xs->local_segment); + Object *obj = obj_get(s->segmentManager, scriptState.xs->objp); + Script *local_script = s->segmentManager->getScriptIfLoaded(scriptState.xs->local_segment); int old_execution_stack_base = s->execution_stack_base; // Used to detect the stack bottom, for "physical" returns const byte *code_buf = NULL; // (Avoid spurious warning) @@ -567,7 +567,7 @@ void run_vm(EngineState *s, int restoring) { scriptState.xs = &(s->_executionStack.back()); s->_executionStackPosChanged = false; - scr = s->seg_manager->getScriptIfLoaded(scriptState.xs->addr.pc.segment); + scr = s->segmentManager->getScriptIfLoaded(scriptState.xs->addr.pc.segment); if (!scr) { // No script? Implicit return via fake instruction buffer warning("Running on non-existant script in segment %x", scriptState.xs->addr.pc.segment); @@ -580,12 +580,12 @@ void run_vm(EngineState *s, int restoring) { scr = NULL; obj = NULL; } else { - obj = obj_get(s->seg_manager, s->_version, scriptState.xs->objp); + obj = obj_get(s->segmentManager, scriptState.xs->objp); code_buf = scr->buf; #ifndef DISABLE_VALIDATIONS code_buf_size = scr->buf_size; #endif - local_script = s->seg_manager->getScriptIfLoaded(scriptState.xs->local_segment); + local_script = s->segmentManager->getScriptIfLoaded(scriptState.xs->local_segment); if (!local_script) { warning("Could not find local script from segment %x", scriptState.xs->local_segment); local_script = NULL; @@ -917,17 +917,22 @@ void run_vm(EngineState *s, int restoring) { gc_countdown(s); scriptState.xs->sp -= (opparams[1] >> 1) + 1; - if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) { - scriptState.xs->sp -= scriptState.restAdjust; - s->restAdjust = 0; // We just used up the scriptState.restAdjust, remember? + + { + bool oldScriptHeader = (s->segmentManager->sciVersion() == SCI_VERSION_0_EARLY); + if (!oldScriptHeader) { + scriptState.xs->sp -= scriptState.restAdjust; + s->restAdjust = 0; // We just used up the scriptState.restAdjust, remember? + } } if (opparams[0] >= (int)((SciEngine*)g_engine)->getKernel()->_kernelFuncs.size()) { error("Invalid kernel function 0x%x requested", opparams[0]); } else { int argc = ASSERT_ARITHMETIC(scriptState.xs->sp[0]); + bool oldScriptHeader = (s->segmentManager->sciVersion() == SCI_VERSION_0_EARLY); - if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) + if (!oldScriptHeader) argc += scriptState.restAdjust; if (((SciEngine*)g_engine)->getKernel()->_kernelFuncs[opparams[0]].signature @@ -947,8 +952,11 @@ void run_vm(EngineState *s, int restoring) { xs_new = &(s->_executionStack.back()); s->_executionStackPosChanged = true; - if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) - scriptState.restAdjust = s->restAdjust; + { + bool oldScriptHeader = (s->segmentManager->sciVersion() == SCI_VERSION_0_EARLY); + if (!oldScriptHeader) + scriptState.restAdjust = s->restAdjust; + } } break; @@ -1038,7 +1046,7 @@ void run_vm(EngineState *s, int restoring) { break; case 0x28: // class - s->r_acc = s->seg_manager->get_class_address((unsigned)opparams[0], SCRIPT_GET_LOCK, + s->r_acc = s->segmentManager->get_class_address((unsigned)opparams[0], SCRIPT_GET_LOCK, scriptState.xs->addr.pc); break; @@ -1058,7 +1066,7 @@ void run_vm(EngineState *s, int restoring) { break; case 0x2b: // super - r_temp = s->seg_manager->get_class_address(opparams[0], SCRIPT_GET_LOAD, scriptState.xs->addr.pc); + r_temp = s->segmentManager->get_class_address(opparams[0], SCRIPT_GET_LOAD, scriptState.xs->addr.pc); if (!r_temp.segment) error("[VM]: Invalid superclass in object"); @@ -1156,7 +1164,7 @@ void run_vm(EngineState *s, int restoring) { case 0x39: // lofsa s->r_acc.segment = scriptState.xs->addr.pc.segment; - if (s->_version >= SCI_VERSION_1_1) { + if (s->resourceManager->sciVersion() >= SCI_VERSION_1_1) { s->r_acc.offset = opparams[0] + local_script->script_size; } else { if (((SciEngine*)g_engine)->getKernel()->hasLofsAbsolute()) @@ -1176,7 +1184,7 @@ void run_vm(EngineState *s, int restoring) { case 0x3a: // lofss r_temp.segment = scriptState.xs->addr.pc.segment; - if (s->_version >= SCI_VERSION_1_1) { + if (s->resourceManager->sciVersion() >= SCI_VERSION_1_1) { r_temp.offset = opparams[0] + local_script->script_size; } else { if (((SciEngine*)g_engine)->getKernel()->hasLofsAbsolute()) @@ -1390,12 +1398,12 @@ void run_vm(EngineState *s, int restoring) { } } -static int _obj_locate_varselector(EngineState *s, Object *obj, Selector slc) { +static int _obj_locate_varselector(SegManager *segManager, Object *obj, Selector slc) { // Determines if obj explicitly defines slc as a varselector // Returns -1 if not found - SciVersion version = s->_version; // for the selector defines + SciVersion version = segManager->sciVersion(); // for the selector defines - if (s->_version < SCI_VERSION_1_1) { + if (version < SCI_VERSION_1_1) { int varnum = obj->variable_names_nr; int selector_name_offset = varnum * 2 + SCRIPT_SELECTOR_OFFSET; int i; @@ -1414,7 +1422,7 @@ static int _obj_locate_varselector(EngineState *s, Object *obj, Selector slc) { int varnum = obj->_variables[1].offset; if (!(obj->_variables[SCRIPT_INFO_SELECTOR].offset & SCRIPT_INFO_CLASS)) - buf = ((byte *) obj_get(s->seg_manager, s->_version, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR])->base_vars); + buf = ((byte *) obj_get(segManager, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR])->base_vars); for (i = 0; i < varnum; i++) if (READ_LE_UINT16(buf + (i << 1)) == slc) // Found it? @@ -1424,7 +1432,7 @@ static int _obj_locate_varselector(EngineState *s, Object *obj, Selector slc) { } } -static int _class_locate_funcselector(EngineState *s, Object *obj, Selector slc) { +static int _class_locate_funcselector(Object *obj, Selector slc, SciVersion version) { // Determines if obj is a class and explicitly defines slc as a funcselector // Does NOT say anything about obj's superclasses, i.e. failure may be // returned even if one of the superclasses defines the funcselector. @@ -1438,14 +1446,14 @@ static int _class_locate_funcselector(EngineState *s, Object *obj, Selector slc) return -1; // Failed } -static SelectorType _lookup_selector_function(EngineState *s, int seg_id, Object *obj, Selector selector_id, reg_t *fptr) { +static SelectorType _lookup_selector_function(SegManager *segManager, int seg_id, Object *obj, Selector selector_id, reg_t *fptr) { int index; - SciVersion version = s->_version; // for the selector defines + SciVersion version = segManager->sciVersion(); // for the selector defines // "recursive" lookup while (obj) { - index = _class_locate_funcselector(s, obj, selector_id); + index = _class_locate_funcselector(obj, selector_id, version); if (index >= 0) { if (fptr) { @@ -1455,22 +1463,23 @@ static SelectorType _lookup_selector_function(EngineState *s, int seg_id, Object return kSelectorMethod; } else { seg_id = obj->_variables[SCRIPT_SUPERCLASS_SELECTOR].segment; - obj = obj_get(s->seg_manager, s->_version, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR]); + obj = obj_get(segManager, obj->_variables[SCRIPT_SUPERCLASS_SELECTOR]); } } return kSelectorNone; } -SelectorType lookup_selector(EngineState *s, reg_t obj_location, Selector selector_id, ObjVarRef *varp, reg_t *fptr) { - Object *obj = obj_get(s->seg_manager, s->_version, obj_location); +SelectorType lookup_selector(SegManager *segManager, reg_t obj_location, Selector selector_id, ObjVarRef *varp, reg_t *fptr) { + Object *obj = obj_get(segManager, obj_location); Object *species; int index; - SciVersion version = s->_version; // for the selector defines + SciVersion version = segManager->sciVersion(); // for the selector defines + bool oldScriptHeader = (version == SCI_VERSION_0_EARLY); // Early SCI versions used the LSB in the selector ID as a read/write // toggle, meaning that we must remove it for selector lookup. - if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) + if (oldScriptHeader) selector_id &= ~1; if (!obj) { @@ -1481,7 +1490,7 @@ SelectorType lookup_selector(EngineState *s, reg_t obj_location, Selector select if (IS_CLASS(obj)) species = obj; else - species = obj_get(s->seg_manager, s->_version, obj->_variables[SCRIPT_SPECIES_SELECTOR]); + species = obj_get(segManager, obj->_variables[SCRIPT_SPECIES_SELECTOR]); if (!obj) { @@ -1490,7 +1499,7 @@ SelectorType lookup_selector(EngineState *s, reg_t obj_location, Selector select return kSelectorNone; } - index = _obj_locate_varselector(s, obj, selector_id); + index = _obj_locate_varselector(segManager, obj, selector_id); if (index >= 0) { // Found it as a variable @@ -1501,7 +1510,7 @@ SelectorType lookup_selector(EngineState *s, reg_t obj_location, Selector select return kSelectorVariable; } - return _lookup_selector_function(s, obj_location.segment, obj, selector_id, fptr); + return _lookup_selector_function(segManager, obj_location.segment, obj, selector_id, fptr); } reg_t script_lookup_export(SegManager *segManager, int script_nr, int export_index) { @@ -1512,19 +1521,19 @@ reg_t script_lookup_export(SegManager *segManager, int script_nr, int export_ind #define INST_LOOKUP_CLASS(id) ((id == 0xffff)? NULL_REG : segManager->get_class_address(id, SCRIPT_GET_LOCK, reg)) -int script_instantiate_common(ResourceManager *resMgr, SegManager *segManager, SciVersion version, int script_nr, Resource **script, Resource **heap, int *was_new) { +int script_instantiate_common(ResourceManager *resourceManager, SegManager *segManager, int script_nr, Resource **script, Resource **heap, int *was_new) { int seg_id; reg_t reg; *was_new = 1; - *script = resMgr->findResource(ResourceId(kResourceTypeScript, script_nr), 0); - if (version >= SCI_VERSION_1_1) - *heap = resMgr->findResource(ResourceId(kResourceTypeHeap, script_nr), 0); + *script = resourceManager->findResource(ResourceId(kResourceTypeScript, script_nr), 0); + if (resourceManager->sciVersion() >= SCI_VERSION_1_1) + *heap = resourceManager->findResource(ResourceId(kResourceTypeHeap, script_nr), 0); - if (!*script || (version >= SCI_VERSION_1_1 && !heap)) { + if (!*script || (resourceManager->sciVersion() >= SCI_VERSION_1_1 && !heap)) { warning("Script 0x%x requested but not found", script_nr); - if (version >= SCI_VERSION_1_1) { + if (resourceManager->sciVersion() >= SCI_VERSION_1_1) { if (*heap) warning("Inconsistency: heap resource WAS found"); else if (*script) @@ -1566,7 +1575,7 @@ int script_instantiate_common(ResourceManager *resMgr, SegManager *segManager, S return seg_id; } -int script_instantiate_sci0(ResourceManager *resMgr, SegManager *segManager, SciVersion version, bool oldScriptHeader, int script_nr) { +int script_instantiate_sci0(ResourceManager *resourceManager, SegManager *segManager, int script_nr) { int objtype; unsigned int objlength; reg_t reg; @@ -1575,8 +1584,10 @@ int script_instantiate_sci0(ResourceManager *resMgr, SegManager *segManager, Sci int magic_pos_adder; // Usually 0; 2 for older SCI versions Resource *script; int was_new; + SciVersion version = resourceManager->sciVersion(); + bool oldScriptHeader = (version == SCI_VERSION_0_EARLY); - seg_id = script_instantiate_common(resMgr, segManager, version, script_nr, &script, NULL, &was_new); + seg_id = script_instantiate_common(resourceManager, segManager, script_nr, &script, NULL, &was_new); if (was_new) return seg_id; @@ -1690,7 +1701,7 @@ int script_instantiate_sci0(ResourceManager *resMgr, SegManager *segManager, Sci // Instantiate the superclass, if neccessary obj->_variables[SCRIPT_SPECIES_SELECTOR] = INST_LOOKUP_CLASS(obj->_variables[SCRIPT_SPECIES_SELECTOR].offset); - base_obj = obj_get(segManager, version, obj->_variables[SCRIPT_SPECIES_SELECTOR]); + base_obj = obj_get(segManager, obj->_variables[SCRIPT_SPECIES_SELECTOR]); obj->variable_names_nr = base_obj->_variables.size(); obj->base_obj = base_obj->base_obj; // Copy base from species class, as we need its selector IDs @@ -1716,14 +1727,14 @@ int script_instantiate_sci0(ResourceManager *resMgr, SegManager *segManager, Sci return reg.segment; // instantiation successful } -int script_instantiate_sci11(ResourceManager *resMgr, SegManager *segManager, SciVersion version, int script_nr) { +int script_instantiate_sci11(ResourceManager *resourceManager, SegManager *segManager, int script_nr) { Resource *script, *heap; int seg_id; int heap_start; reg_t reg; int was_new; - seg_id = script_instantiate_common(resMgr, segManager, version, script_nr, &script, &heap, &was_new); + seg_id = script_instantiate_common(resourceManager, segManager, script_nr, &script, &heap, &was_new); if (was_new) return seg_id; @@ -1753,17 +1764,19 @@ int script_instantiate_sci11(ResourceManager *resMgr, SegManager *segManager, Sc return seg_id; } -int script_instantiate(ResourceManager *resMgr, SegManager *segManager, SciVersion version, int script_nr) { - if (version >= SCI_VERSION_1_1) - return script_instantiate_sci11(resMgr, segManager, version, script_nr); +int script_instantiate(ResourceManager *resourceManager, SegManager *segManager, int script_nr) { + if (resourceManager->sciVersion() >= SCI_VERSION_1_1) + return script_instantiate_sci11(resourceManager, segManager, script_nr); else - return script_instantiate_sci0(resMgr, segManager, version, (version == SCI_VERSION_0_EARLY), script_nr); + return script_instantiate_sci0(resourceManager, segManager, script_nr); } -void script_uninstantiate_sci0(SegManager *segManager, SciVersion version, int script_nr, SegmentId seg) { - reg_t reg = make_reg(seg, ((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader() ? 2 : 0); +void script_uninstantiate_sci0(SegManager *segManager, int script_nr, SegmentId seg) { + bool oldScriptHeader = (segManager->sciVersion() == SCI_VERSION_0_EARLY); + reg_t reg = make_reg(seg, oldScriptHeader ? 2 : 0); int objtype, objlength; Script *scr = segManager->getScript(seg); + SciVersion version = segManager->sciVersion(); // Make a pass over the object in order uninstantiate all superclasses objlength = 0; @@ -1792,7 +1805,7 @@ void script_uninstantiate_sci0(SegManager *segManager, SciVersion version, int s if (scr->getLockers()) scr->decrementLockers(); // Decrease lockers if this is us ourselves } else - script_uninstantiate(segManager, version, superclass_script); + script_uninstantiate(segManager, superclass_script); // Recurse to assure that the superclass lockers number gets decreased } @@ -1804,7 +1817,7 @@ void script_uninstantiate_sci0(SegManager *segManager, SciVersion version, int s } while (objtype != 0); } -void script_uninstantiate(SegManager *segManager, SciVersion version, int script_nr) { +void script_uninstantiate(SegManager *segManager, int script_nr) { SegmentId segment = segManager->segGet(script_nr); Script *scr = segManager->getScriptIfLoaded(segment); @@ -1824,8 +1837,8 @@ void script_uninstantiate(SegManager *segManager, SciVersion version, int script if (segManager->_classtable[i].reg.segment == segment) segManager->_classtable[i].reg = NULL_REG; - if (version < SCI_VERSION_1_1) - script_uninstantiate_sci0(segManager, version, script_nr, segment); + if (segManager->sciVersion() < SCI_VERSION_1_1) + script_uninstantiate_sci0(segManager, script_nr, segment); else warning("FIXME: Add proper script uninstantiation for SCI 1.1"); @@ -1917,8 +1930,9 @@ int game_run(EngineState **_s) { return 0; } -Object *obj_get(SegManager *segManager, SciVersion version, reg_t offset) { +Object *obj_get(SegManager *segManager, reg_t offset) { MemObject *mobj = GET_OBJECT_SEGMENT(*segManager, offset.segment); + SciVersion version = segManager->sciVersion(); Object *obj = NULL; int idx; @@ -1941,8 +1955,9 @@ Object *obj_get(SegManager *segManager, SciVersion version, reg_t offset) { return obj; } -const char *obj_get_name(SegManager *segManager, SciVersion version, reg_t pos) { - Object *obj = obj_get(segManager, version, pos); +const char *obj_get_name(SegManager *segManager, reg_t pos) { + Object *obj = obj_get(segManager, pos); + SciVersion version = segManager->sciVersion(); if (!obj) return "<no such object>"; @@ -1974,7 +1989,7 @@ void shrink_execution_stack(EngineState *s, uint size) { } reg_t* ObjVarRef::getPointer(EngineState *s) const { - Object *o = obj_get(s->seg_manager, s->_version, obj); + Object *o = obj_get(s->segmentManager, obj); if (!o) return 0; return &(o->_variables[varindex]); } diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h index c8f94d5446..e6597c8f4c 100644 --- a/engines/sci/engine/vm.h +++ b/engines/sci/engine/vm.h @@ -37,7 +37,6 @@ namespace Sci { class SegManager; struct EngineState; -typedef int sci_version_t; struct IntMapper; struct Object; class ResourceManager; @@ -448,7 +447,7 @@ void script_free_vm_memory(EngineState *s); /** * Looks up a selector and returns its type and value * varindex is written to iff it is non-NULL and the selector indicates a property of the object. - * @param[in] s The EngineState to use + * @param[in] segManager The Segment Manager * @param[in] obj Address of the object to look the selector up in * @param[in] selectorid The selector to look up * @param[out] varp A reference to the selector, if it is a @@ -465,7 +464,7 @@ void script_free_vm_memory(EngineState *s); * kSelectorMethod if the selector represents a * method */ -SelectorType lookup_selector(EngineState *s, reg_t obj, Selector selectorid, +SelectorType lookup_selector(SegManager *segManager, reg_t obj, Selector selectorid, ObjVarRef *varp, reg_t *fptr); /** @@ -483,13 +482,12 @@ reg_t script_lookup_export(SegManager *segManager, int script_nr, int export_ind * increased. All scripts containing superclasses of this script are loaded * recursively as well, unless 'recursive' is set to zero. The * complementary function is "script_uninstantiate()" below. - * @param[in] resMgr The resource manager + * @param[in] resourceManager The resource manager * @param[in] segManager The segment manager - * @param[in] version The SCI version to use * @param[in] script_nr The script number to load * @return The script's segment ID or 0 if out of heap */ -int script_instantiate(ResourceManager *resMgr, SegManager *segManager, SciVersion version, int script_nr); +int script_instantiate(ResourceManager *resourceManager, SegManager *segManager, int script_nr); /** * Decreases the numer of lockers of a script and unloads it if that number @@ -500,7 +498,7 @@ int script_instantiate(ResourceManager *resMgr, SegManager *segManager, SciVersi * @param[in] version The SCI version to use * @param[in] script_nr The script number that is requestet to be unloaded */ -void script_uninstantiate(SegManager *segManager, SciVersion version, int script_nr); +void script_uninstantiate(SegManager *segManager, int script_nr); /** * Initializes an SCI game @@ -568,28 +566,28 @@ void quit_vm(); /** * Allocates "kernel" memory and returns a handle suitable to be passed on * to SCI scripts - * @param[in] s Pointer to the EngineState to operate on - * @param[in] type A free-form type description string (static) - * @param[in] space The space to allocate - * @return The handle + * @param[in] segManager The Segment Manager + * @param[in] type A free-form type description string (static) + * @param[in] space The space to allocate + * @return The handle */ -reg_t kalloc(EngineState *s, const char *type, int space); +reg_t kalloc(SegManager *segManager, const char *type, int space); /** * Returns a pointer to "kernel" memory based on the handle - * @param[in] s Pointer to the EngineState to operate on - * @param[in] handle The handle to use - * @return A pointer to the allocated memory + * @param[in] segManager The Segment Manager + * @param[in] handle The handle to use + * @return A pointer to the allocated memory */ -byte *kmem(EngineState *s, reg_t handle); +byte *kmem(SegManager *segManager, reg_t handle); /** * Frees all "kernel" memory associated with a handle - * @param[in] s Pointer to the EngineState to operate on - * @param[in] handle The handle to free - * @return 0 on success, 1 otherwise + * @param[in] segManager The Segment Manager + * @param[in] handle The handle to free + * @return 0 on success, 1 otherwise */ -int kfree(EngineState *s, reg_t handle); +int kfree(SegManager *segManager, reg_t handle); /** * Determines the name of an object @@ -600,7 +598,7 @@ int kfree(EngineState *s, reg_t handle); * in a static buffer and need not be freed (neither may * it be modified). */ -const char *obj_get_name(SegManager *segManager, SciVersion version, reg_t pos); +const char *obj_get_name(SegManager *segManager, reg_t pos); /** * Retrieves an object from the specified location @@ -608,7 +606,7 @@ const char *obj_get_name(SegManager *segManager, SciVersion version, reg_t pos); * @param[in] offset The object's offset * @return The object in question, or NULL if there is none */ -Object *obj_get(SegManager *segManager, SciVersion version, reg_t offset); +Object *obj_get(SegManager *segManager, reg_t offset); /** * Shrink execution stack to size. |