diff options
author | Filippos Karapetis | 2009-07-11 23:45:54 +0000 |
---|---|---|
committer | Filippos Karapetis | 2009-07-11 23:45:54 +0000 |
commit | 31a0c8090513023596351174aa48f787ca6384b3 (patch) | |
tree | 56a0bf0b62d543f533fe86e479a7edb080ea548d /engines/sci/engine | |
parent | 116d2254119476f58b6b135b7a06a207f38fb5d0 (diff) | |
download | scummvm-rg350-31a0c8090513023596351174aa48f787ca6384b3.tar.gz scummvm-rg350-31a0c8090513023596351174aa48f787ca6384b3.tar.bz2 scummvm-rg350-31a0c8090513023596351174aa48f787ca6384b3.zip |
Moved the kernel and the vocabulary outside of the engine state (they're static data, which never changes during a game)
svn-id: r42398
Diffstat (limited to 'engines/sci/engine')
-rw-r--r-- | engines/sci/engine/game.cpp | 14 | ||||
-rw-r--r-- | engines/sci/engine/kernel.h | 8 | ||||
-rw-r--r-- | engines/sci/engine/kgraphics.cpp | 34 | ||||
-rw-r--r-- | engines/sci/engine/kmisc.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/kmovement.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/kscripts.cpp | 6 | ||||
-rw-r--r-- | engines/sci/engine/ksound.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/kstring.cpp | 7 | ||||
-rw-r--r-- | engines/sci/engine/said.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/said.y | 2 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cpp | 14 | ||||
-rw-r--r-- | engines/sci/engine/scriptdebug.cpp | 10 | ||||
-rw-r--r-- | engines/sci/engine/seg_manager.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/state.cpp | 3 | ||||
-rw-r--r-- | engines/sci/engine/state.h | 5 | ||||
-rw-r--r-- | engines/sci/engine/vm.cpp | 34 | ||||
-rw-r--r-- | engines/sci/engine/vm.h | 2 |
17 files changed, 65 insertions, 90 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 5b4c30f6b3..0a74ac32e4 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -87,7 +87,7 @@ int _reset_graphics_input(EngineState *s) { s->priority_first = 42; // Priority zone 0 ends here - if (s->_kernel->usesOldGfxFunctions()) + if (((SciEngine*)g_engine)->getKernel()->usesOldGfxFunctions()) s->priority_last = 200; else s->priority_last = 190; @@ -257,7 +257,7 @@ static int create_class_table_sci0(EngineState *s) { Resource *script = s->resmgr->findResource(ResourceId(kResourceTypeScript, scriptnr), 0); if (script) { - if (s->_kernel->hasOldScriptHeader()) + if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) magic_offset = seeker = 2; else magic_offset = seeker = 0; @@ -327,9 +327,6 @@ int script_init_engine(EngineState *s) { s->kernel_opt_flags = 0; - s->_kernel = new Kernel(s->resmgr); - s->_vocabulary = new Vocabulary(s->resmgr); - if (s->_version >= SCI_VERSION_1_1) result = create_class_table_sci11(s); else @@ -375,7 +372,7 @@ int script_init_engine(EngineState *s) { s->bp_list = NULL; // No breakpoints defined s->have_bp = 0; - if (s->_kernel->hasLofsAbsolute()) + if (((SciEngine*)g_engine)->getKernel()->hasLofsAbsolute()) s->seg_manager->setExportWidth(1); else s->seg_manager->setExportWidth(0); @@ -412,11 +409,6 @@ void script_free_engine(EngineState *s) { script_free_vm_memory(s); debug(2, "Freeing state-dependant data"); - - delete s->_vocabulary; - s->_vocabulary = 0; - delete s->_kernel; - s->_kernel = 0; } void script_free_breakpoints(EngineState *s) { diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index 17997e4a20..15f7c9fcf3 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -205,7 +205,7 @@ enum SelectorInvocation { kContinueOnInvalidSelector = 1 }; -#define GET_SEL32(_o_, _slc_) read_selector(s, _o_, s->_kernel->_selectorMap._slc_, __FILE__, __LINE__) +#define GET_SEL32(_o_, _slc_) read_selector(s, _o_, ((SciEngine*)g_engine)->getKernel()->_selectorMap._slc_, __FILE__, __LINE__) #define GET_SEL32V(_o_, _slc_) (GET_SEL32(_o_, _slc_).offset) #define GET_SEL32SV(_o_, _slc_) ((int16)(GET_SEL32(_o_, _slc_).offset)) /* Retrieves a selector from an object @@ -216,8 +216,8 @@ enum SelectorInvocation { ** selector_map_t and mapped in script.c. */ -#define PUT_SEL32(_o_, _slc_, _val_) write_selector(s, _o_, s->_kernel->_selectorMap._slc_, _val_, __FILE__, __LINE__) -#define PUT_SEL32V(_o_, _slc_, _val_) write_selector(s, _o_, s->_kernel->_selectorMap._slc_, make_reg(0, _val_), __FILE__, __LINE__) +#define PUT_SEL32(_o_, _slc_, _val_) write_selector(s, _o_, ((SciEngine*)g_engine)->getKernel()->_selectorMap._slc_, _val_, __FILE__, __LINE__) +#define PUT_SEL32V(_o_, _slc_, _val_) write_selector(s, _o_, ((SciEngine*)g_engine)->getKernel()->_selectorMap._slc_, make_reg(0, _val_), __FILE__, __LINE__) /* Writes a selector value to an object ** Parameters: (reg_t) object: The address of the object which the selector should be written to ** (selector_name) selector: The selector to read @@ -229,7 +229,7 @@ enum SelectorInvocation { #define INV_SEL(_object_, _selector_, _noinvalid_) \ - s, _object_, s->_kernel->_selectorMap._selector_, _noinvalid_, funct_nr, argv, argc, __FILE__, __LINE__ + s, _object_, ((SciEngine*)g_engine)->getKernel()->_selectorMap._selector_, _noinvalid_, funct_nr, argv, argc, __FILE__, __LINE__ /* Kludge for use with invoke_selector(). Used for compatibility with compilers that can't ** handle vararg macros. */ diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index d46ce3b938..c7086ddef7 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -164,7 +164,7 @@ int _find_view_priority(EngineState *s, int y) { return j; return 14; // Maximum } else { - if (!s->_kernel->usesOldGfxFunctions()) + if (!((SciEngine*)g_engine)->getKernel()->usesOldGfxFunctions()) return SCI0_VIEW_PRIORITY_14_ZONES(y); else return SCI0_VIEW_PRIORITY(y) == 15 ? 14 : SCI0_VIEW_PRIORITY(y); @@ -172,7 +172,7 @@ int _find_view_priority(EngineState *s, int y) { } int _find_priority_band(EngineState *s, int nr) { - if (!s->_kernel->usesOldGfxFunctions() && (nr < 0 || nr > 14)) { + if (!((SciEngine*)g_engine)->getKernel()->usesOldGfxFunctions() && (nr < 0 || nr > 14)) { if (nr == 15) return 0xffff; else { @@ -181,7 +181,7 @@ int _find_priority_band(EngineState *s, int nr) { return 0; } - if (s->_kernel->usesOldGfxFunctions() && (nr < 0 || nr > 15)) { + if (((SciEngine*)g_engine)->getKernel()->usesOldGfxFunctions() && (nr < 0 || nr > 15)) { warning("Attempt to get priority band %d", nr); return 0; } @@ -191,7 +191,7 @@ int _find_priority_band(EngineState *s, int nr) { else { int retval; - if (!s->_kernel->usesOldGfxFunctions()) + if (!((SciEngine*)g_engine)->getKernel()->usesOldGfxFunctions()) retval = SCI0_PRIORITY_BAND_FIRST_14_ZONES(nr); else retval = SCI0_PRIORITY_BAND_FIRST(nr); @@ -696,7 +696,7 @@ void _k_dirloop(reg_t obj, uint16 angle, EngineState *s, int funct_nr, int argc, angle %= 360; - if (!s->_kernel->hasOldScriptHeader()) { + if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) { if (angle < 45) loop = 3; else if (angle < 136) @@ -1002,7 +1002,7 @@ reg_t kDrawPic(EngineState *s, int funct_nr, int argc, reg_t *argv) { gfx_color_t transparent = s->wm_port->_bgcolor; int picFlags = DRAWPIC01_FLAG_FILL_NORMALLY; - if (s->_kernel->usesOldGfxFunctions()) + if (((SciEngine*)g_engine)->getKernel()->usesOldGfxFunctions()) add_to_pic = (argc > 2) ? argv[2].toSint16() : false; dp.nr = argv[0].toSint16(); @@ -1056,7 +1056,7 @@ reg_t kDrawPic(EngineState *s, int funct_nr, int argc, reg_t *argv) { s->priority_first = 42; - if (s->_kernel->usesOldGfxFunctions()) + if (((SciEngine*)g_engine)->getKernel()->usesOldGfxFunctions()) s->priority_last = 200; else s->priority_last = 190; @@ -1079,7 +1079,7 @@ Common::Rect set_base(EngineState *s, reg_t object) { x = GET_SEL32SV(object, x); original_y = y = GET_SEL32SV(object, y); - if (s->_kernel->_selectorMap.z > -1) + if (((SciEngine*)g_engine)->getKernel()->_selectorMap.z > -1) z = GET_SEL32SV(object, z); else z = 0; @@ -1133,7 +1133,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, s->_kernel->_selectorMap.brLeft, NULL, NULL) != kSelectorVariable) + if (lookup_selector(s, 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 @@ -1214,7 +1214,7 @@ Common::Rect get_nsrect(EngineState *s, reg_t object, byte clip) { x = GET_SEL32SV(object, x); y = GET_SEL32SV(object, y); - if (s->_kernel->_selectorMap.z > -1) + if (((SciEngine*)g_engine)->getKernel()->_selectorMap.z > -1) z = GET_SEL32SV(object, z); else z = 0; @@ -1238,7 +1238,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, s->_kernel->_selectorMap.nsTop, NULL, NULL) != kSelectorVariable) { + if (lookup_selector(s, object, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsTop, NULL, NULL) != kSelectorVariable) { return; } // This isn't fatal @@ -1724,7 +1724,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, s->_kernel->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable; + int has_nsrect = lookup_selector(s, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable; if (has_nsrect) { int temp; @@ -1746,7 +1746,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, s->_kernel->_selectorMap.nsBottom, NULL, NULL)); + fprintf(stderr, "Not lsRecting %04x:%04x because %d\n", PRINT_REG(obj), lookup_selector(s, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL)); #endif if (widget->signal & _K_VIEW_SIG_FLAG_HIDDEN) @@ -1900,7 +1900,7 @@ static GfxDynView *_k_make_dynview_obj(EngineState *s, reg_t obj, int options, i loop = oldloop = sign_extend_byte(GET_SEL32V(obj, loop)); cel = oldcel = sign_extend_byte(GET_SEL32V(obj, cel)); - if (s->_kernel->_selectorMap.palette) + if (((SciEngine*)g_engine)->getKernel()->_selectorMap.palette) palette = GET_SEL32V(obj, palette); else palette = 0; @@ -1923,7 +1923,7 @@ static GfxDynView *_k_make_dynview_obj(EngineState *s, reg_t obj, int options, i } ObjVarRef under_bitsp; - if (lookup_selector(s, obj, s->_kernel->_selectorMap.underBits, &(under_bitsp), NULL) != kSelectorVariable) { + if (lookup_selector(s, 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)); @@ -1931,7 +1931,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, s->_kernel->_selectorMap.signal, &(signalp), NULL) != kSelectorVariable) { + if (lookup_selector(s, 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)); @@ -2024,7 +2024,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, s->_kernel->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable; + int has_nsrect = (view->_ID <= 0) ? 0 : lookup_selector(s, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable; int oldsignal = view->signal; _k_set_now_seen(s, obj); diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp index 7e0aca5b7a..c693009b35 100644 --- a/engines/sci/engine/kmisc.cpp +++ b/engines/sci/engine/kmisc.cpp @@ -240,7 +240,7 @@ reg_t kMemory(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t kStub(EngineState *s, int funct_nr, int argc, reg_t *argv) { char tmpbuf[200]; sprintf(tmpbuf, "Unimplemented syscall: %s[%x] (", - s->_kernel->getKernelName(funct_nr).c_str(), funct_nr); + ((SciEngine*)g_engine)->getKernel()->getKernelName(funct_nr).c_str(), funct_nr); for (int i = 0; i < argc; i++) { char tmpbuf2[20]; @@ -257,7 +257,7 @@ reg_t kStub(EngineState *s, int funct_nr, int argc, reg_t *argv) { } reg_t kNOP(EngineState *s, int funct_nr, int argc, reg_t *argv) { - warning("Kernel function 0x%02x (%s) invoked: unmapped", funct_nr, s->_kernel->_kernelFuncs[funct_nr].orig_name.c_str()); + warning("Kernel function 0x%02x (%s) invoked: unmapped", funct_nr, ((SciEngine*)g_engine)->getKernel()->_kernelFuncs[funct_nr].orig_name.c_str()); return NULL_REG; } diff --git a/engines/sci/engine/kmovement.cpp b/engines/sci/engine/kmovement.cpp index 90db630bfa..8774224f60 100644 --- a/engines/sci/engine/kmovement.cpp +++ b/engines/sci/engine/kmovement.cpp @@ -267,7 +267,7 @@ static void bresenham_autodetect(EngineState *s) { return; } - if (lookup_selector(s, motion_class, s->_kernel->_selectorMap.doit, NULL, &fptr) != kSelectorMethod) { + if (lookup_selector(s, 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; @@ -362,7 +362,7 @@ reg_t kDoBresen(EngineState *s, int funct_nr, int argc, reg_t *argv) { debugC(2, kDebugLevelBresen, "New data: (x,y)=(%d,%d), di=%d\n", x, y, bdi); - if (s->_kernel->_selectorMap.cantBeHere != -1) + if (((SciEngine*)g_engine)->getKernel()->_selectorMap.cantBeHere != -1) invoke_selector(INV_SEL(client, cantBeHere, kStopOnInvalidSelector), 0); else invoke_selector(INV_SEL(client, canBeHere, kStopOnInvalidSelector), 0); diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp index d82f8ff132..df25e11729 100644 --- a/engines/sci/engine/kscripts.cpp +++ b/engines/sci/engine/kscripts.cpp @@ -43,7 +43,7 @@ reg_t read_selector(EngineState *s, reg_t object, Selector selector_id, const ch void write_selector(EngineState *s, reg_t object, Selector selector_id, reg_t value, const char *fname, int line) { ObjVarRef address; - if ((selector_id < 0) || (selector_id > (int)s->_kernel->getSelectorNamesSize())) { + if ((selector_id < 0) || (selector_id > (int)((SciEngine*)g_engine)->getKernel()->getSelectorNamesSize())) { warning("Attempt to write to invalid selector %d of" " object at %04x:%04x (%s L%d).", selector_id, PRINT_REG(object), fname, line); return; @@ -51,7 +51,7 @@ void write_selector(EngineState *s, reg_t object, Selector selector_id, reg_t va if (lookup_selector(s, object, selector_id, &address, NULL) != kSelectorVariable) warning("Selector '%s' of object at %04x:%04x could not be" - " written to (%s L%d)", s->_kernel->getSelectorName(selector_id).c_str(), PRINT_REG(object), fname, line); + " written to (%s L%d)", ((SciEngine*)g_engine)->getKernel()->getSelectorName(selector_id).c_str(), PRINT_REG(object), fname, line); else *address.getPointer(s) = value; } @@ -72,7 +72,7 @@ int invoke_selector(EngineState *s, reg_t object, int selector_id, SelectorInvoc if (slc_type == kSelectorNone) { warning("Selector '%s' of object at %04x:%04x could not be invoked (%s L%d)", - s->_kernel->getSelectorName(selector_id).c_str(), PRINT_REG(object), fname, line); + ((SciEngine*)g_engine)->getKernel()->getSelectorName(selector_id).c_str(), PRINT_REG(object), fname, line); if (noinvalid == kStopOnInvalidSelector) error("[Kernel] Not recoverable: VM was halted\n"); return 1; diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp index 95c2eaab1d..8c113d35a3 100644 --- a/engines/sci/engine/ksound.cpp +++ b/engines/sci/engine/ksound.cpp @@ -988,9 +988,9 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { * Used for synthesized music playback */ reg_t kDoSound(EngineState *s, int funct_nr, int argc, reg_t *argv) { - if (s->_kernel->usesSci1SoundFunctions()) + if (((SciEngine*)g_engine)->getKernel()->usesSci1SoundFunctions()) return kDoSound_SCI1(s, funct_nr, argc, argv); - else if (s->_kernel->usesSci01SoundFunctions()) + else if (((SciEngine*)g_engine)->getKernel()->usesSci01SoundFunctions()) return kDoSound_SCI01(s, funct_nr, argc, argv); else return kDoSound_SCI0(s, funct_nr, argc, argv); diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index c572906285..b6bb404d5b 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -95,7 +95,7 @@ reg_t kSaid(EngineState *s, int funct_nr, int argc, reg_t *argv) { #ifdef DEBUG_PARSER debugC(2, kDebugLevelParser, "Said block:", 0); - s->_vocabulary->decipherSaidBlock(said_block); + ((SciEngine*)g_engine)->getVocabulary()->decipherSaidBlock(said_block); #endif if (s->parser_event.isNull() || (GET_SEL32V(s->parser_event, claimed))) { @@ -190,10 +190,11 @@ reg_t kParse(EngineState *s, int funct_nr, int argc, reg_t *argv) { char *error; ResultWordList words; reg_t event = argv[1]; + Vocabulary *voc = ((SciEngine*)g_engine)->getVocabulary(); s->parser_event = event; - bool res = s->_vocabulary->tokenizeString(words, string, &error); + bool res = voc->tokenizeString(words, string, &error); s->parser_valid = 0; /* not valid */ if (res && !words.empty()) { @@ -211,7 +212,7 @@ reg_t kParse(EngineState *s, int funct_nr, int argc, reg_t *argv) { debugC(2, kDebugLevelParser, " Type[%04x] Group[%04x]\n", i->_class, i->_group); #endif - if (s->_vocabulary->parseGNF(s->parser_nodes, words)) + if (voc->parseGNF(s->parser_nodes, words)) syntax_fail = 1; /* Building a tree failed */ if (syntax_fail) { diff --git a/engines/sci/engine/said.cpp b/engines/sci/engine/said.cpp index 921fa4e599..b1d174b30f 100644 --- a/engines/sci/engine/said.cpp +++ b/engines/sci/engine/said.cpp @@ -2449,7 +2449,7 @@ int said(EngineState *s, byte *spec, int verbose) { if (s->parser_valid) { if (said_parse_spec(s, spec)) { printf("Offending spec was: "); - s->_vocabulary->decipherSaidBlock(spec); + ((SciEngine*)g_engine)->getVocabulary()->decipherSaidBlock(spec); return SAID_NO_MATCH; } diff --git a/engines/sci/engine/said.y b/engines/sci/engine/said.y index c1c8424cb5..e7c225b3e6 100644 --- a/engines/sci/engine/said.y +++ b/engines/sci/engine/said.y @@ -805,7 +805,7 @@ int said(EngineState *s, byte *spec, int verbose) { if (s->parser_valid) { if (said_parse_spec(s, spec)) { warning("Offending spec was: "); - s->_vocabulary->decypherSaidBlock(spec); + ((SciEngine*)g_engine)->getVocabulary()->decypherSaidBlock(spec); return SAID_NO_MATCH; } diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index e167e7eca8..d5f094b540 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -497,7 +497,7 @@ static SegmentId find_unique_seg_by_type(SegManager *self, int type) { } static byte *find_unique_script_block(EngineState *s, byte *buf, int type) { - if (s->_kernel->hasOldScriptHeader()) + if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) buf += 2; do { @@ -756,13 +756,6 @@ 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); - // static VM/Kernel information: - assert(0 == retval->_kernel); - retval->_kernel = s->_kernel; // needs to be initialized before _reset_graphics_input is called -// s->_kernel = 0; // FIXME: We should set s->_kernel to 0 here, -// else it could be freed when the old EngineState is freed. Luckily, this freeing currently -// never happens, so we don't need to. - // Copy some old data retval->gfx_state = s->gfx_state; retval->sound_mute = s->sound_mute; @@ -821,11 +814,6 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { retval->game_start_time = g_system->getMillis() - retval->game_time * 1000; // static parser information: - assert(0 == retval->_vocabulary); - retval->_vocabulary = s->_vocabulary; -// s->_vocabulary = 0; // FIXME: We should set s->_vocabulary to 0 here, -// else it could be freed when the old EngineState is freed. Luckily, this freeing currently -// never happens, so we don't need to. retval->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE); diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 7f5f201079..92cfe9daf3 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -148,7 +148,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod if (print_bw_tag) printf("[%c] ", opsize ? 'B' : 'W'); - printf("%s", s->_kernel->getOpcode(opcode).name.c_str()); + printf("%s", ((SciEngine*)g_engine)->getKernel()->getOpcode(opcode).name.c_str()); i = 0; while (g_opcode_formats[opcode][i]) { @@ -183,8 +183,8 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod } if (opcode == op_callk) - printf(" %s[%x]", (param_value < s->_kernel->_kernelFuncs.size()) ? - ((param_value < s->_kernel->getKernelNamesSize()) ? s->_kernel->getKernelName(param_value).c_str() : "[Unknown(postulated)]") + printf(" %s[%x]", (param_value < ((SciEngine*)g_engine)->getKernel()->_kernelFuncs.size()) ? + ((param_value < ((SciEngine*)g_engine)->getKernel()->getKernelNamesSize()) ? ((SciEngine*)g_engine)->getKernel()->getKernelName(param_value).c_str() : "[Unknown(postulated)]") : "<invalid>", param_value); else printf(opsize ? " %02x" : " %04x", param_value); @@ -238,7 +238,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod int stackframe = (scr[pos.offset + 2] >> 1) + (scriptState.restAdjust); int argc = ((scriptState.xs->sp)[- stackframe - 1]).offset; - if (!s->_kernel->hasOldScriptHeader()) + if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) argc += (scriptState.restAdjust); printf(" Kernel params: ("); @@ -273,7 +273,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod if (!name) name = "<invalid>"; - printf(" %s::%s[", name, (selector > s->_kernel->getSelectorNamesSize()) ? "<invalid>" : selector_name(s, selector)); + 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)) { case kSelectorMethod: diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 74486ef015..6752ba3e56 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -138,7 +138,7 @@ void SegManager::setScriptSize(Script &scr, EngineState *s, int script_nr) { if (!script || (s->_version >= SCI_VERSION_1_1 && !heap)) { error("SegManager::setScriptSize: failed to load %s", !script ? "script" : "heap"); } - if (s->_kernel->hasOldScriptHeader()) { + if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) { scr.buf_size = script->size + READ_LE_UINT16(script->data) * 2; //locals_size = READ_LE_UINT16(script->data) * 2; } else if (s->_version < SCI_VERSION_1_1) { diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp index c43fe9b6de..38320c29cc 100644 --- a/engines/sci/engine/state.cpp +++ b/engines/sci/engine/state.cpp @@ -113,9 +113,6 @@ EngineState::EngineState(ResourceManager *res, sci_version_t version, uint32 fla seg_manager = 0; gc_countdown = 0; - _vocabulary = 0; - _kernel = 0; - successor = 0; } diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h index 1759b26dcb..b41e9e383a 100644 --- a/engines/sci/engine/state.h +++ b/engines/sci/engine/state.h @@ -257,9 +257,6 @@ public: MessageState _msgState; - Vocabulary *_vocabulary; - Kernel *_kernel; - EngineState *successor; /**< Successor of this state: Used for restoring */ private: @@ -283,7 +280,7 @@ PaletteEntry get_pic_color(EngineState *s, int color); // misleading. A different name (and a different place for declaring this) // would be highly welcome. static inline reg_t not_register(EngineState *s, reg_t r) { - if (s->_kernel->_selectorMap.cantBeHere != -1) + if (((SciEngine*)g_engine)->getKernel()->_selectorMap.cantBeHere != -1) return make_reg(0, !r.offset); else return r; diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index d220547c92..99b5a86e53 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -312,7 +312,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, send_obj), s->_kernel->getSelectorName(selector).c_str()); + sprintf(method_name, "%s::%s", obj_get_name(s, send_obj), ((SciEngine*)g_engine)->getKernel()->getSelectorName(selector).c_str()); bp = s->bp_list; while (bp) { @@ -952,26 +952,26 @@ void run_vm(EngineState *s, int restoring) { gc_countdown(s); scriptState.xs->sp -= (opparams[1] >> 1) + 1; - if (!s->_kernel->hasOldScriptHeader()) { + if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) { scriptState.xs->sp -= scriptState.restAdjust; s->restAdjust = 0; // We just used up the scriptState.restAdjust, remember? } - if (opparams[0] >= (int)s->_kernel->_kernelFuncs.size()) { + if (opparams[0] >= (int)((SciEngine*)g_engine)->getKernel()->_kernelFuncs.size()) { error("Invalid kernel function 0x%x requested\n", opparams[0]); } else { int argc = ASSERT_ARITHMETIC(scriptState.xs->sp[0]); - if (!s->_kernel->hasOldScriptHeader()) + if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) argc += scriptState.restAdjust; - if (s->_kernel->_kernelFuncs[opparams[0]].signature + if (((SciEngine*)g_engine)->getKernel()->_kernelFuncs[opparams[0]].signature && !kernel_matches_signature(s, - s->_kernel->_kernelFuncs[opparams[0]].signature, argc, + ((SciEngine*)g_engine)->getKernel()->_kernelFuncs[opparams[0]].signature, argc, scriptState.xs->sp + 1)) { error("[VM] Invalid arguments to kernel call %x\n", opparams[0]); } else { - s->r_acc = s->_kernel->_kernelFuncs[opparams[0]].fun(s, opparams[0], + s->r_acc = ((SciEngine*)g_engine)->getKernel()->_kernelFuncs[opparams[0]].fun(s, opparams[0], argc, scriptState.xs->sp + 1); } // Call kernel function @@ -982,7 +982,7 @@ void run_vm(EngineState *s, int restoring) { xs_new = &(s->_executionStack.back()); s->_executionStackPosChanged = true; - if (!s->_kernel->hasOldScriptHeader()) + if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) scriptState.restAdjust = s->restAdjust; } @@ -1194,7 +1194,7 @@ void run_vm(EngineState *s, int restoring) { if (s->_version >= SCI_VERSION_1_1) { s->r_acc.offset = opparams[0] + local_script->script_size; } else { - if (s->_kernel->hasLofsAbsolute()) + if (((SciEngine*)g_engine)->getKernel()->hasLofsAbsolute()) s->r_acc.offset = opparams[0]; else s->r_acc.offset = scriptState.xs->addr.pc.offset + opparams[0]; @@ -1214,7 +1214,7 @@ void run_vm(EngineState *s, int restoring) { if (s->_version >= SCI_VERSION_1_1) { r_temp.offset = opparams[0] + local_script->script_size; } else { - if (s->_kernel->hasLofsAbsolute()) + if (((SciEngine*)g_engine)->getKernel()->hasLofsAbsolute()) r_temp.offset = opparams[0]; else r_temp.offset = scriptState.xs->addr.pc.offset + opparams[0]; @@ -1500,7 +1500,7 @@ SelectorType lookup_selector(EngineState *s, reg_t obj_location, Selector select // 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 (s->_kernel->hasOldScriptHeader()) + if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) selector_id &= ~1; if (!obj) { @@ -1659,7 +1659,7 @@ int script_instantiate_sci0(EngineState *s, int script_nr) { Script *scr = s->seg_manager->getScript(seg_id); - if (s->_kernel->hasOldScriptHeader()) { + if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) { // int locals_nr = READ_LE_UINT16(script->data); @@ -1835,7 +1835,7 @@ int script_instantiate(EngineState *s, int script_nr) { } void script_uninstantiate_sci0(EngineState *s, int script_nr, SegmentId seg) { - reg_t reg = make_reg(seg, s->_kernel->hasOldScriptHeader() ? 2 : 0); + reg_t reg = make_reg(seg, ((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader() ? 2 : 0); int objtype, objlength; Script *scr = s->seg_manager->getScript(seg); @@ -1879,7 +1879,7 @@ void script_uninstantiate_sci0(EngineState *s, int script_nr, SegmentId seg) { } void script_uninstantiate(EngineState *s, int script_nr) { - reg_t reg = make_reg(0, s->_kernel->hasOldScriptHeader() ? 2 : 0); + reg_t reg = make_reg(0, ((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader() ? 2 : 0); reg.segment = s->seg_manager->segGet(script_nr); Script *scr = script_locate_by_segment(s, reg.segment); @@ -1938,7 +1938,7 @@ static EngineState *_game_run(EngineState *&s, int restoring) { script_init_engine(s); game_init(s); sfx_reset_player(); - _init_stack_base_with_selector(s, s->_kernel->_selectorMap.play); + _init_stack_base_with_selector(s, ((SciEngine*)g_engine)->getKernel()->_selectorMap.play); send_selector(s, s->game_obj, s->game_obj, s->stack_base, 2, s->stack_base); @@ -1957,7 +1957,7 @@ static EngineState *_game_run(EngineState *&s, int restoring) { debugC(2, kDebugLevelVM, "Restarting with replay()\n"); s->_executionStack.clear(); // Restart with replay - _init_stack_base_with_selector(s, s->_kernel->_selectorMap.replay); + _init_stack_base_with_selector(s, ((SciEngine*)g_engine)->getKernel()->_selectorMap.replay); send_selector(s, s->game_obj, s->game_obj, s->stack_base, 2, s->stack_base); } @@ -1976,7 +1976,7 @@ int game_run(EngineState **_s) { EngineState *s = *_s; debugC(2, kDebugLevelVM, "Calling %s::play()\n", s->_gameName.c_str()); - _init_stack_base_with_selector(s, s->_kernel->_selectorMap.play); // Call the play selector + _init_stack_base_with_selector(s, ((SciEngine*)g_engine)->getKernel()->_selectorMap.play); // Call the play selector // Now: Register the first element on the execution stack- if (!send_selector(s, s->game_obj, s->game_obj, s->stack_base, 2, s->stack_base)) { diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h index 1472fae97c..f711570d11 100644 --- a/engines/sci/engine/vm.h +++ b/engines/sci/engine/vm.h @@ -419,7 +419,7 @@ void script_debug(EngineState *s, bool bp); * @return 0 on success, 1 if vocab.996 (the class table) is missing * or corrupted */ -int script_init_engine(EngineState *s); +int script_init_engine(EngineState *); /** * Sets the gamestate's save_dir to the parameter path |