aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine
diff options
context:
space:
mode:
authorPaweł Kołodziejski2009-02-20 17:05:47 +0000
committerPaweł Kołodziejski2009-02-20 17:05:47 +0000
commit61231c2a366de64d7e09697a6ca78869dcd8cf4b (patch)
treed8cdfee8417cc30f608d90bbdf8a99a35405ded2 /engines/sci/engine
parentac4fe7a4bc492f1d83f80f2fef4f6c2b652bee1b (diff)
downloadscummvm-rg350-61231c2a366de64d7e09697a6ca78869dcd8cf4b.tar.gz
scummvm-rg350-61231c2a366de64d7e09697a6ca78869dcd8cf4b.tar.bz2
scummvm-rg350-61231c2a366de64d7e09697a6ca78869dcd8cf4b.zip
formating
svn-id: r38604
Diffstat (limited to 'engines/sci/engine')
-rw-r--r--engines/sci/engine/kscripts.cpp138
1 files changed, 49 insertions, 89 deletions
diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp
index 0576a4f6e4..6d8b3eb933 100644
--- a/engines/sci/engine/kscripts.cpp
+++ b/engines/sci/engine/kscripts.cpp
@@ -27,8 +27,7 @@
#include "sci/include/engine.h"
#include "sci/engine/kernel_types.h"
-reg_t
-read_selector(state_t *s, reg_t object, selector_t selector_id, const char *file, int line) {
+reg_t read_selector(state_t *s, reg_t object, selector_t selector_id, const char *file, int line) {
reg_t *address;
if (lookup_selector(s, object, selector_id, &address, NULL) != SELECTOR_VARIABLE)
@@ -37,32 +36,24 @@ read_selector(state_t *s, reg_t object, selector_t selector_id, const char *file
return *address;
}
-
-void
-write_selector(state_t *s, reg_t object, selector_t selector_id, reg_t value,
- const char *fname, int line) {
+void write_selector(state_t *s, reg_t object, selector_t selector_id, reg_t value, const char *fname, int line) {
reg_t *address;
if ((selector_id < 0) || (selector_id > s->selector_names_nr)) {
SCIkwarn(SCIkWARNING, "Attempt to write to invalid selector %d of"
- " object at "PREG" (%s L%d).\n", selector_id,
- PRINT_REG(object), fname, line);
+ " object at "PREG" (%s L%d).\n", selector_id, PRINT_REG(object), fname, line);
return;
}
if (lookup_selector(s, object, selector_id, &address, NULL) != SELECTOR_VARIABLE)
SCIkwarn(SCIkWARNING, "Selector '%s' of object at %04x could not be"
- " written to (%s L%d)\n",
- s->selector_names[selector_id], object, fname, line);
+ " written to (%s L%d)\n", s->selector_names[selector_id], object, fname, line);
else
*address = value;
-
}
-int
-invoke_selector(state_t *s, reg_t object, int selector_id, int noinvalid, int kfunct,
- stack_ptr_t k_argp, int k_argc, /* Kernel function argp/argc */
- const char *fname, int line, int argc, ...) {
+int invoke_selector(state_t *s, reg_t object, int selector_id, int noinvalid, int kfunct,
+ stack_ptr_t k_argp, int k_argc, const char *fname, int line, int argc, ...) {
va_list argp;
int i;
int framesize = 2 + 1 * argc;
@@ -70,10 +61,10 @@ invoke_selector(state_t *s, reg_t object, int selector_id, int noinvalid, int kf
int slc_type;
stack_ptr_t stackframe = k_argp + k_argc;
- exec_stack_t *xstack; /* Execution stack */
+ exec_stack_t *xstack; // Execution stack
- stackframe[0] = make_reg(0, selector_id); /* The selector we want to call */
- stackframe[1] = make_reg(0, argc); /* Argument count */
+ 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);
@@ -84,61 +75,52 @@ invoke_selector(state_t *s, reg_t object, int selector_id, int noinvalid, int kf
KERNEL_OOPS("Not recoverable: VM was halted\n");
return 1;
}
- if (slc_type == SELECTOR_VARIABLE) /* Swallow silently */
+ if (slc_type == SELECTOR_VARIABLE) // Swallow silently
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 */
+ stackframe[2 + i] = arg; // Write each argument
}
va_end(argp);
- /* Write "kernel" call to the stack, for debugging: */
- xstack = add_exec_stack_entry(s, NULL_REG, NULL, NULL_REG,
- k_argc, k_argp - 1, 0, NULL_REG,
+ // Write "kernel" call to the stack, for debugging:
+ xstack = add_exec_stack_entry(s, NULL_REG, NULL, NULL_REG, k_argc, k_argp - 1, 0, NULL_REG,
s->execution_stack_pos, SCI_XS_CALLEE_LOCALS);
- xstack->selector = -42 - kfunct; /* Evil debugging hack to identify kernel function */
+ xstack->selector = -42 - kfunct; // Evil debugging hack to identify kernel function
xstack->type = EXEC_STACK_TYPE_KERNEL;
- /* Now commit the actual function: */
- xstack = send_selector(s, object, object,
- stackframe, framesize, stackframe);
+ // Now commit the actual function:
+ xstack = send_selector(s, object, object, stackframe, framesize, stackframe);
xstack->sp += argc + 2;
xstack->fp += argc + 2;
- run_vm(s, 0); /* Start a new vm */
+ run_vm(s, 0); // Start a new vm
- --(s->execution_stack_pos); /* Get rid of the extra stack entry */
+ --(s->execution_stack_pos); // Get rid of the extra stack entry
return 0;
}
-
-int
-is_object(state_t *s, reg_t object) {
+int is_object(state_t *s, reg_t object) {
return obj_get(s, object) != NULL;
}
-
-/* kLoad(restype, resnrs ... ):
-** Loads arbitrary resources of type 'restype' with resource numbers 'resnrs'
-** This implementation ignores all resource numbers except the first one.
-*/
-reg_t
-kLoad(state_t *s, int funct_nr, int argc, reg_t *argv) {
+// Loads arbitrary resources of type 'restype' with resource numbers 'resnrs'
+// This implementation ignores all resource numbers except the first one.
+reg_t kLoad(state_t *s, int funct_nr, int argc, reg_t *argv) {
int restype = KP_UINT(argv[0]);
int resnr = KP_UINT(argv[1]);
- if (restype == sci_memory)/* Request to dynamically allocate hunk memory for later use */
+ if (restype == sci_memory) // Request to dynamically allocate hunk memory for later use
return kalloc(s, "kLoad()", resnr);
- return make_reg(0, ((restype << 11) | resnr)); /* Return the resource identifier as handle */
+ return make_reg(0, ((restype << 11) | resnr)); // Return the resource identifier as handle
}
-reg_t
-kLock(state_t *s, int funct_nr, int argc, reg_t *argv) {
+reg_t kLock(state_t *s, int funct_nr, int argc, reg_t *argv) {
int restype = UKPV(0) & 0x7f;
int resnr = UKPV(1);
int state = argc > 2 ? UKPV(2) : 1;
@@ -157,11 +139,8 @@ kLock(state_t *s, int funct_nr, int argc, reg_t *argv) {
return s->r_acc;
}
-/* kUnload():
-** Unloads an arbitrary resource of type 'restype' with resource numbber 'resnr'
-*/
-reg_t
-kUnLoad(state_t *s, int funct_nr, int argc, reg_t *argv) {
+// Unloads an arbitrary resource of type 'restype' with resource numbber 'resnr'
+reg_t kUnLoad(state_t *s, int funct_nr, int argc, reg_t *argv) {
int restype = KP_UINT(argv[0]);
reg_t resnr = argv[1];
@@ -171,16 +150,13 @@ kUnLoad(state_t *s, int funct_nr, int argc, reg_t *argv) {
return s->r_acc;
}
-
-reg_t
-kClone(state_t *s, int funct_nr, int argc, reg_t *argv) {
+reg_t kClone(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t parent_addr = argv[0];
object_t *parent_obj = obj_get(s, parent_addr);
reg_t clone_addr;
- clone_t *clone_obj; /* same as object_t* */
+ clone_t *clone_obj; // same as object_t*
int varblock_size;
-
if (!parent_obj) {
SCIkwarn(SCIkERROR, "Attempt to clone non-object/class at "PREG" failed", PRINT_REG(parent_addr));
return NULL_REG;
@@ -201,7 +177,7 @@ kClone(state_t *s, int funct_nr, int argc, reg_t *argv) {
clone_obj->variables = (reg_t*)sci_malloc(varblock_size);
memcpy(clone_obj->variables, parent_obj->variables, varblock_size);
- /* Mark as clone */
+ // 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))
@@ -212,12 +188,9 @@ kClone(state_t *s, int funct_nr, int argc, reg_t *argv) {
return clone_addr;
}
+extern void _k_view_list_mark_free(state_t *s, reg_t off);
-extern void
- _k_view_list_mark_free(state_t *s, reg_t off); /* kgraphics.c */
-
-reg_t
-kDisposeClone(state_t *s, int funct_nr, int argc, reg_t *argv) {
+reg_t kDisposeClone(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t victim_addr = argv[0];
clone_t *victim_obj = obj_get(s, victim_addr);
word underBits;
@@ -229,8 +202,8 @@ kDisposeClone(state_t *s, int funct_nr, int argc, reg_t *argv) {
}
if (victim_obj->variables[SCRIPT_INFO_SELECTOR].offset != SCRIPT_INFO_CLONE) {
- /* SCIkwarn("Attempt to dispose something other than a clone at %04x\n", offset); */
- /* SCI silently ignores this behaviour; some games actually depend on it */
+ //SCIkwarn("Attempt to dispose something other than a clone at %04x\n", offset);
+ // SCI silently ignores this behaviour; some games actually depend on it
return s->r_acc;
}
@@ -239,7 +212,7 @@ kDisposeClone(state_t *s, int funct_nr, int argc, reg_t *argv) {
SCIkwarn(SCIkWARNING, "Clone "PREG" was cleared with underBits set\n", PRINT_REG(victim_addr));
}
#if 0
- if (s->dyn_views) { /* Free any widget associated with the clone */
+ if (s->dyn_views) { // Free any widget associated with the clone
gfxw_widget_t *widget = gfxw_set_id(gfxw_remove_ID(s->dyn_views, offset), GFXW_NO_ID);
if (widget && s->bg_widgets)
@@ -249,17 +222,13 @@ kDisposeClone(state_t *s, int funct_nr, int argc, reg_t *argv) {
victim_obj->flags |= OBJECT_FLAG_FREED;
- _k_view_list_mark_free(s, victim_addr); /* Free on view list, if neccessary */
+ _k_view_list_mark_free(s, victim_addr); // Free on view list, if neccessary
return s->r_acc;
}
-
-/* kScriptID(script, index):
-** Returns script dispatch address index in the supplied script
-*/
-reg_t
-kScriptID(state_t *s, int funct_nr, int argc, reg_t *argv) {
+// Returns script dispatch address index in the supplied script
+reg_t kScriptID(state_t *s, int funct_nr, int argc, reg_t *argv) {
int script = KP_UINT(argv[0]);
int index = KP_UINT(KP_ALT(1, NULL_REG));
@@ -280,21 +249,19 @@ kScriptID(state_t *s, int funct_nr, int argc, reg_t *argv) {
}
if (index > scr->exports_nr) {
- SCIkwarn(SCIkERROR, "Dispatch index too big: %d > %d\n",
- index, scr->exports_nr);
+ SCIkwarn(SCIkERROR, "Dispatch index too big: %d > %d\n", index, scr->exports_nr);
return NULL_REG;
}
return make_reg(scriptid, sm_validate_export_func(&s->seg_manager, index, scriptid));
}
-
-reg_t
-kDisposeScript(state_t *s, int funct_nr, int argc, reg_t *argv) {
+reg_t kDisposeScript(state_t *s, int funct_nr, int argc, reg_t *argv) {
int script = argv[0].offset;
- /* Work around QfG1 graveyard bug */
- if (argv[0].segment) return s->r_acc;
+ // Work around QfG1 graveyard bug
+ if (argv[0].segment)
+ return s->r_acc;
if (sm_script_is_loaded(&(s->seg_manager), script, SCRIPT_ID)) {
int id = sm_seg_get(&(s->seg_manager), script);
@@ -308,28 +275,21 @@ kDisposeScript(state_t *s, int funct_nr, int argc, reg_t *argv) {
return s->r_acc;
}
-int
-is_heap_object(state_t *s, reg_t pos) {
+int is_heap_object(state_t *s, reg_t pos) {
object_t *obj = obj_get(s, pos);
- return (obj != NULL
- && (!(obj->flags & OBJECT_FLAG_FREED))
- && (!sm_script_is_marked_as_deleted(&s->seg_manager, pos.segment)));
+ return (obj != NULL && (!(obj->flags & OBJECT_FLAG_FREED)) && (!sm_script_is_marked_as_deleted(&s->seg_manager, pos.segment)));
}
-reg_t
-kIsObject(state_t *s, int funct_nr, int argc, reg_t *argv) {
- if (argv[0].offset == 0xffff) /* Treated specially */
+reg_t kIsObject(state_t *s, int funct_nr, int argc, reg_t *argv) {
+ if (argv[0].offset == 0xffff) // Treated specially
return NULL_REG;
else
return make_reg(0, is_heap_object(s, argv[0]));
}
-reg_t
-kRespondsTo(state_t *s, int funct_nr, int argc, reg_t *argv) {
+reg_t kRespondsTo(state_t *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = argv[0];
int selector = KP_UINT(argv[1]);
- return make_reg(0, is_heap_object(s, obj)
- && lookup_selector(s, obj, selector, NULL, NULL) != SELECTOR_NONE);
+ return make_reg(0, is_heap_object(s, obj) && lookup_selector(s, obj, selector, NULL, NULL) != SELECTOR_NONE);
}
-