diff options
author | Walter van Niftrik | 2010-01-28 20:29:45 +0000 |
---|---|---|
committer | Walter van Niftrik | 2010-01-28 20:29:45 +0000 |
commit | 639fb4c3897f5d7c191ed084475549d6065cc18b (patch) | |
tree | 76cb535e2365a9f089b3dbdd4a77337c190b9e09 /engines/sci | |
parent | 493350e905a7840aa2a1076b17d18d7156379517 (diff) | |
download | scummvm-rg350-639fb4c3897f5d7c191ed084475549d6065cc18b.tar.gz scummvm-rg350-639fb4c3897f5d7c191ed084475549d6065cc18b.tar.bz2 scummvm-rg350-639fb4c3897f5d7c191ed084475549d6065cc18b.zip |
SCI: Cleanup
svn-id: r47649
Diffstat (limited to 'engines/sci')
-rw-r--r-- | engines/sci/engine/kernel.h | 2 | ||||
-rw-r--r-- | engines/sci/engine/klists.cpp | 40 | ||||
-rw-r--r-- | engines/sci/engine/selector.cpp | 29 |
3 files changed, 25 insertions, 46 deletions
diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index 384f386ddd..0fc7ad4190 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -239,6 +239,8 @@ reg_t read_selector(SegManager *segMan, reg_t object, Selector selector_id); void write_selector(SegManager *segMan, reg_t object, Selector selector_id, reg_t value); int invoke_selector(EngineState *s, reg_t object, int selector_id, SelectorInvocation noinvalid, StackPtr k_argp, int k_argc, int argc, ...); +int invoke_selector_argv(EngineState *s, reg_t object, int selector_id, SelectorInvocation noinvalid, + StackPtr k_argp, int k_argc, int argc, const reg_t *argv); /******************** Text functionality ********************/ diff --git a/engines/sci/engine/klists.cpp b/engines/sci/engine/klists.cpp index 48de11c8a3..b58d6c6747 100644 --- a/engines/sci/engine/klists.cpp +++ b/engines/sci/engine/klists.cpp @@ -535,18 +535,7 @@ reg_t kListEachElementDo(EngineState *s, int argc, reg_t *argv) { write_selector(s->_segMan, curObject, slc, argv[2]); } } else { - // FIXME: Yes, this is an ugly hack... - if (argc == 2) { - invoke_selector(s, curObject, slc, kContinueOnInvalidSelector, argv, argc, 0); - } else if (argc == 3) { - invoke_selector(s, curObject, slc, kContinueOnInvalidSelector, argv, argc, 1, argv[2]); - } else if (argc == 4) { - invoke_selector(s, curObject, slc, kContinueOnInvalidSelector, argv, argc, 2, argv[2], argv[3]); - } else if (argc == 5) { - invoke_selector(s, curObject, slc, kContinueOnInvalidSelector, argv, argc, 3, argv[2], argv[3], argv[4]); - } else { - warning("kListEachElementDo: called with %d params", argc); - } + invoke_selector_argv(s, curObject, slc, kContinueOnInvalidSelector, argv, argc, argc - 2, argv + 2); } // Lookup node again, since the nodetable it was in may have been reallocated @@ -556,7 +545,6 @@ reg_t kListEachElementDo(EngineState *s, int argc, reg_t *argv) { curNode = s->_segMan->lookupNode(curAddress); } - return s->r_acc; } @@ -580,18 +568,7 @@ reg_t kListFirstTrue(EngineState *s, int argc, reg_t *argv) { // Can this happen with variable selectors? warning("kListFirstTrue: Attempted to access a variable selector"); } else { - // FIXME: Yes, this is an ugly hack... - if (argc == 2) { - invoke_selector(s, curObject, slc, kContinueOnInvalidSelector, argv, argc, 0); - } else if (argc == 3) { - invoke_selector(s, curObject, slc, kContinueOnInvalidSelector, argv, argc, 1, argv[2]); - } else if (argc == 4) { - invoke_selector(s, curObject, slc, kContinueOnInvalidSelector, argv, argc, 2, argv[2], argv[3]); - } else if (argc == 5) { - invoke_selector(s, curObject, slc, kContinueOnInvalidSelector, argv, argc, 3, argv[2], argv[3], argv[4]); - } else { - warning("kListFirstTrue: called with %d params", argc); - } + invoke_selector_argv(s, curObject, slc, kContinueOnInvalidSelector, argv, argc, argc - 2, argv + 2); // Check if the result is true if (!s->r_acc.isNull()) @@ -629,18 +606,7 @@ reg_t kListAllTrue(EngineState *s, int argc, reg_t *argv) { // Can this happen with variable selectors? warning("kListAllTrue: Attempted to access a variable selector"); } else { - // FIXME: Yes, this is an ugly hack... - if (argc == 2) { - invoke_selector(s, curObject, slc, kContinueOnInvalidSelector, argv, argc, 0); - } else if (argc == 3) { - invoke_selector(s, curObject, slc, kContinueOnInvalidSelector, argv, argc, 1, argv[2]); - } else if (argc == 4) { - invoke_selector(s, curObject, slc, kContinueOnInvalidSelector, argv, argc, 2, argv[2], argv[3]); - } else if (argc == 5) { - invoke_selector(s, curObject, slc, kContinueOnInvalidSelector, argv, argc, 3, argv[2], argv[3], argv[4]); - } else { - warning("kListAllTrue: called with %d params", argc); - } + invoke_selector_argv(s, curObject, slc, kContinueOnInvalidSelector, argv, argc, argc - 2, argv + 2); // Check if the result isn't true if (s->r_acc.isNull()) diff --git a/engines/sci/engine/selector.cpp b/engines/sci/engine/selector.cpp index 5893d3c295..e3abe10dde 100644 --- a/engines/sci/engine/selector.cpp +++ b/engines/sci/engine/selector.cpp @@ -53,9 +53,8 @@ void write_selector(SegManager *segMan, reg_t object, Selector selector_id, reg_ *address.getPointer(segMan) = value; } -int invoke_selector(EngineState *s, reg_t object, int selector_id, SelectorInvocation noinvalid, - StackPtr k_argp, int k_argc, int argc, ...) { - va_list argp; +int invoke_selector_argv(EngineState *s, reg_t object, int selector_id, SelectorInvocation noinvalid, + StackPtr k_argp, int k_argc, int argc, const reg_t *argv) { int i; int framesize = 2 + 1 * argc; reg_t address; @@ -80,12 +79,8 @@ int invoke_selector(EngineState *s, reg_t object, int selector_id, SelectorInvoc return 0; } - va_start(argp, argc); - for (i = 0; i < argc; i++) { - reg_t arg = va_arg(argp, reg_t); - stackframe[2 + i] = arg; // Write each argument - } - va_end(argp); + for (i = 0; i < argc; i++) + stackframe[2 + i] = argv[i]; // Write each argument ExecStack *xstack; @@ -100,6 +95,22 @@ int invoke_selector(EngineState *s, reg_t object, int selector_id, SelectorInvoc return 0; } +int invoke_selector(EngineState *s, reg_t object, int selector_id, SelectorInvocation noinvalid, + StackPtr k_argp, int k_argc, int argc, ...) { + va_list argp; + reg_t *args = new reg_t[argc]; + + va_start(argp, argc); + for (int i = 0; i < argc; i++) + args[i] = va_arg(argp, reg_t); + va_end(argp); + + int retval = invoke_selector_argv(s, object, selector_id, noinvalid, k_argp, k_argc, argc, args); + + delete[] args; + return retval; +} + static int _obj_locate_varselector(SegManager *segMan, Object *obj, Selector slc) { // Determines if obj explicitly defines slc as a varselector // Returns -1 if not found |