aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine
diff options
context:
space:
mode:
authorFilippos Karapetis2009-08-25 15:14:29 +0000
committerFilippos Karapetis2009-08-25 15:14:29 +0000
commitac025f4294336f2cbc3c5de62149e47f3645b141 (patch)
tree03640f9b8d7f196475d5b1d7f8ba7ae33a9a0f90 /engines/sci/engine
parent70a63a8dbda110a107897eab3c82a5fe2810ab6e (diff)
downloadscummvm-rg350-ac025f4294336f2cbc3c5de62149e47f3645b141.tar.gz
scummvm-rg350-ac025f4294336f2cbc3c5de62149e47f3645b141.tar.bz2
scummvm-rg350-ac025f4294336f2cbc3c5de62149e47f3645b141.zip
- Replaced more cases of EngineState parameters
- Made some version comparisons for old SCI0 versions easier to read - Removed the GET_SEL32SV macro svn-id: r43729
Diffstat (limited to 'engines/sci/engine')
-rw-r--r--engines/sci/engine/gc.cpp2
-rw-r--r--engines/sci/engine/kernel.cpp21
-rw-r--r--engines/sci/engine/kernel.h15
-rw-r--r--engines/sci/engine/kernel_types.h2
-rw-r--r--engines/sci/engine/kevent.cpp4
-rw-r--r--engines/sci/engine/kfile.cpp66
-rw-r--r--engines/sci/engine/kgraphics.cpp106
-rw-r--r--engines/sci/engine/klists.cpp3
-rw-r--r--engines/sci/engine/kmenu.cpp7
-rw-r--r--engines/sci/engine/kmisc.cpp8
-rw-r--r--engines/sci/engine/kmovement.cpp38
-rw-r--r--engines/sci/engine/kpathing.cpp20
-rw-r--r--engines/sci/engine/kscripts.cpp13
-rw-r--r--engines/sci/engine/ksound.cpp6
-rw-r--r--engines/sci/engine/kstring.cpp49
-rw-r--r--engines/sci/engine/seg_manager.cpp4
-rw-r--r--engines/sci/engine/state.cpp12
-rw-r--r--engines/sci/engine/stringfrag.cpp30
-rw-r--r--engines/sci/engine/vm.cpp20
-rw-r--r--engines/sci/engine/vm.h4
20 files changed, 234 insertions, 196 deletions
diff --git a/engines/sci/engine/gc.cpp b/engines/sci/engine/gc.cpp
index 41d454d637..88eee3e17b 100644
--- a/engines/sci/engine/gc.cpp
+++ b/engines/sci/engine/gc.cpp
@@ -102,7 +102,7 @@ reg_t_hash_map *find_all_used_references(EngineState *s) {
wm.push(es.objp);
wm.push(es.sendp);
if (es.type == EXEC_STACK_TYPE_VARSELECTOR)
- wm.push(*(es.getVarPointer(s)));
+ wm.push(*(es.getVarPointer(s->segmentManager)));
}
}
diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp
index 013d8cb65b..33f4daf4c3 100644
--- a/engines/sci/engine/kernel.cpp
+++ b/engines/sci/engine/kernel.cpp
@@ -422,6 +422,7 @@ void Kernel::detectSciFeatures() {
void Kernel::loadSelectorNames() {
Resource *r = _resourceManager->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SNAMES), 0);
+ bool oldScriptHeader = (_resourceManager->sciVersion() == SCI_VERSION_0_EARLY);
if (!r) { // No such resource?
// Check if we have a table for this game
@@ -433,7 +434,7 @@ void Kernel::loadSelectorNames() {
for (uint32 i = 0; i < staticSelectorTable.size(); i++) {
_selectorNames.push_back(staticSelectorTable[i]);
- if (_resourceManager->sciVersion() == SCI_VERSION_0_EARLY)
+ if (oldScriptHeader)
_selectorNames.push_back(staticSelectorTable[i]);
}
@@ -452,7 +453,7 @@ 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 (_resourceManager->sciVersion() == SCI_VERSION_0_EARLY)
+ if (oldScriptHeader)
_selectorNames.push_back(tmp);
}
}
@@ -714,14 +715,14 @@ const char *kernel_argtype_description(int type) {
return argtype_description[sci_ffs(type)];
}
-bool kernel_matches_signature(EngineState *s, const char *sig, int argc, const reg_t *argv) {
+bool kernel_matches_signature(SegManager *segManager, const char *sig, int argc, const reg_t *argv) {
// Always "match" if no signature is given
if (!sig)
return true;
while (*sig && argc) {
if ((*sig & KSIG_ANY) != KSIG_ANY) {
- int type = determine_reg_type(s->segmentManager, *argv, *sig & KSIG_ALLOW_INV);
+ int type = determine_reg_type(segManager, *argv, *sig & KSIG_ALLOW_INV);
if (!type) {
warning("[KERN] Could not determine type of ref %04x:%04x; failing signature check", PRINT_REG(*argv));
@@ -750,9 +751,9 @@ bool kernel_matches_signature(EngineState *s, const char *sig, int argc, const r
return (*sig == 0 || (*sig & KSIG_ELLIPSIS));
}
-static void *_kernel_dereference_pointer(EngineState *s, reg_t pointer, int entries, int align) {
+static void *_kernel_dereference_pointer(SegManager *segManager, reg_t pointer, int entries, int align) {
int maxsize;
- void *retval = s->segmentManager->dereference(pointer, &maxsize);
+ void *retval = segManager->dereference(pointer, &maxsize);
if (!retval)
return NULL;
@@ -770,12 +771,12 @@ static void *_kernel_dereference_pointer(EngineState *s, reg_t pointer, int entr
}
-byte *kernel_dereference_bulk_pointer(EngineState *s, reg_t pointer, int entries) {
- return (byte*)_kernel_dereference_pointer(s, pointer, entries, 1);
+byte *kernel_dereference_bulk_pointer(SegManager *segManager, reg_t pointer, int entries) {
+ return (byte*)_kernel_dereference_pointer(segManager, pointer, entries, 1);
}
-reg_t *kernel_dereference_reg_pointer(EngineState *s, reg_t pointer, int entries) {
- return (reg_t*)_kernel_dereference_pointer(s, pointer, entries, sizeof(reg_t));
+reg_t *kernel_dereference_reg_pointer(SegManager *segManager, reg_t pointer, int entries) {
+ return (reg_t*)_kernel_dereference_pointer(segManager, pointer, entries, sizeof(reg_t));
}
void Kernel::setDefaultKernelNames() {
diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h
index 3ad54c9d48..46d7b82217 100644
--- a/engines/sci/engine/kernel.h
+++ b/engines/sci/engine/kernel.h
@@ -187,9 +187,8 @@ enum SelectorInvocation {
kContinueOnInvalidSelector = 1
};
-#define GET_SEL32(_o_, _slc_) read_selector(s, _o_, ((SciEngine*)g_engine)->getKernel()->_selectorMap._slc_, __FILE__, __LINE__)
+#define GET_SEL32(_o_, _slc_) read_selector(segManager, _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
** Parameters: (reg_t) object: The address of the object which the selector should be read from
** (selector_name) selector: The selector to read
@@ -198,8 +197,8 @@ enum SelectorInvocation {
** selector_map_t and mapped in script.c.
*/
-#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__)
+#define PUT_SEL32(_o_, _slc_, _val_) write_selector(segManager, _o_, ((SciEngine*)g_engine)->getKernel()->_selectorMap._slc_, _val_, __FILE__, __LINE__)
+#define PUT_SEL32V(_o_, _slc_, _val_) write_selector(segManager, _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
@@ -217,8 +216,8 @@ enum SelectorInvocation {
*/
-reg_t read_selector(EngineState *s, reg_t object, Selector selector_id, const char *fname, int line);
-void write_selector(EngineState *s, reg_t object, Selector selector_id, reg_t value, const char *fname, int line);
+reg_t read_selector(SegManager *segManager, reg_t object, Selector selector_id, const char *fname, int line);
+void write_selector(SegManager *segManager, reg_t object, Selector selector_id, reg_t value, const char *fname, int line);
int invoke_selector(EngineState *s, reg_t object, int selector_id, SelectorInvocation noinvalid, int kfunct,
StackPtr k_argp, int k_argc, const char *fname, int line, int argc, ...);
@@ -260,8 +259,8 @@ bool is_object(SegManager *segManager, reg_t obj);
* if not enugh entries were available.
* reg_t dereferenciation also assures alignedness of data.
*/
-reg_t *kernel_dereference_reg_pointer(EngineState *s, reg_t pointer, int entries);
-byte *kernel_dereference_bulk_pointer(EngineState *s, reg_t pointer, int entries);
+reg_t *kernel_dereference_reg_pointer(SegManager *segManager, reg_t pointer, int entries);
+byte *kernel_dereference_bulk_pointer(SegManager *segManager, reg_t pointer, int entries);
#define kernel_dereference_char_pointer(state, pointer, entries) (char*)kernel_dereference_bulk_pointer(state, pointer, entries)
/******************** Priority macros/functions ********************/
diff --git a/engines/sci/engine/kernel_types.h b/engines/sci/engine/kernel_types.h
index c8281a1fdd..bec57f5174 100644
--- a/engines/sci/engine/kernel_types.h
+++ b/engines/sci/engine/kernel_types.h
@@ -75,7 +75,7 @@ namespace Sci {
* @param argv argument list
* @return true if the signature was matched, false otherwise
*/
-bool kernel_matches_signature(EngineState *s, const char *sig, int argc, const reg_t *argv);
+bool kernel_matches_signature(SegManager *segManager, const char *sig, int argc, const reg_t *argv);
/**
* Determines the type of the object indicated by reg.
diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp
index bac1d08d78..d5846c2daa 100644
--- a/engines/sci/engine/kevent.cpp
+++ b/engines/sci/engine/kevent.cpp
@@ -41,6 +41,7 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {
sci_event_t e;
int oldx, oldy;
int modifier_mask = s->resourceManager->sciVersion() <= SCI_VERSION_01 ? SCI_EVM_ALL : SCI_EVM_NO_FOOLOCK;
+ SegManager *segManager = s->segmentManager;
// If there's a simkey pending, and the game wants a keyboard event, use the
// simkey instead of a normal event
@@ -152,6 +153,7 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kMapKeyToDir(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = argv[0];
+ SegManager *segManager = s->segmentManager;
if (GET_SEL32V(obj, type) == SCI_EVT_KEYBOARD) { // Keyboard
int mover = -1;
@@ -201,6 +203,7 @@ reg_t kMapKeyToDir(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kGlobalToLocal(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = argc ? argv[0] : NULL_REG; // Can this really happen? Lars
+ SegManager *segManager = s->segmentManager;
if (obj.segment) {
int x = GET_SEL32V(obj, x);
@@ -216,6 +219,7 @@ reg_t kGlobalToLocal(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kLocalToGlobal(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = argc ? argv[0] : NULL_REG; // Can this really happen? Lars
+ SegManager *segManager = s->segmentManager;
if (obj.segment) {
int x = GET_SEL32V(obj, x);
diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp
index c03e69c6d0..a028671140 100644
--- a/engines/sci/engine/kfile.cpp
+++ b/engines/sci/engine/kfile.cpp
@@ -196,7 +196,7 @@ void file_open(EngineState *s, const char *filename, int mode) {
}
reg_t kFOpen(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- char *name = kernel_dereference_char_pointer(s, argv[0], 0);
+ char *name = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
int mode = argv[1].toUint16();
debug(3, "kFOpen(%s,0x%x)", name, mode);
@@ -249,7 +249,7 @@ void fwrite_wrapper(EngineState *s, int handle, char *data, int length) {
reg_t kFPuts(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int handle = argv[0].toUint16();
- char *data = kernel_dereference_char_pointer(s, argv[1], 0);
+ char *data = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
fwrite_wrapper(s, handle, data, strlen(data));
return s->r_acc;
@@ -306,7 +306,7 @@ static void fseek_wrapper(EngineState *s, int handle, int offset, int whence) {
}
reg_t kFGets(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- char *dest = kernel_dereference_char_pointer(s, argv[0], 0);
+ char *dest = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
int maxsize = argv[1].toUint16();
int handle = argv[2].toUint16();
@@ -319,7 +319,7 @@ reg_t kFGets(EngineState *s, int funct_nr, int argc, reg_t *argv) {
* Writes the cwd to the supplied address and returns the address in acc.
*/
reg_t kGetCWD(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- char *targetaddr = kernel_dereference_char_pointer(s, argv[0], 0);
+ char *targetaddr = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
// We do not let the scripts see the file system, instead pretending
// we are always in the same directory.
@@ -355,8 +355,8 @@ reg_t kDeviceInfo(EngineState *s, int funct_nr, int argc, reg_t *argv) {
switch (mode) {
case K_DEVICE_INFO_GET_DEVICE:
- input_s = kernel_dereference_char_pointer(s, argv[1], 0);
- output_s = kernel_dereference_char_pointer(s, argv[2], 0);
+ input_s = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
+ output_s = kernel_dereference_char_pointer(s->segmentManager, argv[2], 0);
assert(input_s != output_s);
strcpy(output_s, "/");
@@ -364,15 +364,15 @@ reg_t kDeviceInfo(EngineState *s, int funct_nr, int argc, reg_t *argv) {
break;
case K_DEVICE_INFO_GET_CURRENT_DEVICE:
- output_s = kernel_dereference_char_pointer(s, argv[1], 0);
+ output_s = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
strcpy(output_s, "/");
debug(3, "K_DEVICE_INFO_GET_CURRENT_DEVICE() -> %s", output_s);
break;
case K_DEVICE_INFO_PATHS_EQUAL: {
- char *path1_s = kernel_dereference_char_pointer(s, argv[1], 0);
- char *path2_s = kernel_dereference_char_pointer(s, argv[2], 0);
+ char *path1_s = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
+ char *path2_s = kernel_dereference_char_pointer(s->segmentManager, argv[2], 0);
debug(3, "K_DEVICE_INFO_PATHS_EQUAL(%s,%s)", path1_s, path2_s);
return make_reg(0, Common::matchString(path2_s, path1_s, true));
@@ -380,7 +380,7 @@ reg_t kDeviceInfo(EngineState *s, int funct_nr, int argc, reg_t *argv) {
break;
case K_DEVICE_INFO_IS_FLOPPY:
- input_s = kernel_dereference_char_pointer(s, argv[1], 0);
+ input_s = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
debug(3, "K_DEVICE_INFO_IS_FLOPPY(%s)", input_s);
return NULL_REG; /* Never */
@@ -389,8 +389,8 @@ reg_t kDeviceInfo(EngineState *s, int funct_nr, int argc, reg_t *argv) {
** for more information on our workaround for this.
*/
case K_DEVICE_INFO_GET_SAVECAT_NAME: {
- output_s = kernel_dereference_char_pointer(s, argv[1], 0);
- game_prefix = kernel_dereference_char_pointer(s, argv[2], 0);
+ output_s = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
+ game_prefix = kernel_dereference_char_pointer(s->segmentManager, argv[2], 0);
sprintf(output_s, "__throwaway");
debug(3, "K_DEVICE_INFO_GET_SAVECAT_NAME(%s) -> %s", game_prefix, output_s);
@@ -398,8 +398,8 @@ reg_t kDeviceInfo(EngineState *s, int funct_nr, int argc, reg_t *argv) {
break;
case K_DEVICE_INFO_GET_SAVEFILE_NAME: {
- output_s = kernel_dereference_char_pointer(s, argv[1], 0);
- game_prefix = kernel_dereference_char_pointer(s, argv[2], 0);
+ output_s = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
+ game_prefix = kernel_dereference_char_pointer(s->segmentManager, argv[2], 0);
int savegame_id = argv[3].toUint16();
sprintf(output_s, "__throwaway");
debug(3, "K_DEVICE_INFO_GET_SAVEFILE_NAME(%s,%d) -> %s", game_prefix, savegame_id, output_s);
@@ -421,7 +421,7 @@ reg_t kGetSaveDir(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kCheckFreeSpace(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- char *path = kernel_dereference_char_pointer(s, argv[0], 0);
+ char *path = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
debug(3, "kCheckFreeSpace(%s)", path);
// We simply always pretend that there is enough space.
@@ -479,7 +479,7 @@ void listSavegames(Common::Array<SavegameDesc> &saves) {
}
reg_t kCheckSaveGame(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- char *game_id = kernel_dereference_char_pointer(s, argv[0], 0);
+ char *game_id = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
int savedir_nr = argv[1].toUint16();
debug(3, "kCheckSaveGame(%s, %d)", game_id, savedir_nr);
@@ -515,10 +515,10 @@ reg_t kCheckSaveGame(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kGetSaveFiles(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- char *game_id = kernel_dereference_char_pointer(s, argv[0], 0);
- char *nametarget = kernel_dereference_char_pointer(s, argv[1], 0);
+ char *game_id = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
+ char *nametarget = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
reg_t nametarget_base = argv[1];
- reg_t *nameoffsets = kernel_dereference_reg_pointer(s, argv[2], 0);
+ reg_t *nameoffsets = kernel_dereference_reg_pointer(s->segmentManager, argv[2], 0);
debug(3, "kGetSaveFiles(%s,%s)", game_id, nametarget);
@@ -565,11 +565,11 @@ reg_t kGetSaveFiles(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kSaveGame(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- char *game_id = kernel_dereference_char_pointer(s, argv[0], 0);
+ char *game_id = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
int savedir_nr = argv[1].toUint16();
int savedir_id; // Savegame ID, derived from savedir_nr and the savegame ID list
- char *game_description = kernel_dereference_char_pointer(s, argv[2], 0);
- char *version = argc > 3 ? strdup(kernel_dereference_char_pointer(s, argv[3], 0)) : NULL;
+ char *game_description = kernel_dereference_char_pointer(s->segmentManager, argv[2], 0);
+ char *version = argc > 3 ? strdup(kernel_dereference_char_pointer(s->segmentManager, argv[3], 0)) : NULL;
debug(3, "kSaveGame(%s,%d,%s,%s)", game_id, savedir_nr, game_description, version);
s->game_version = version;
@@ -638,7 +638,7 @@ reg_t kSaveGame(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kRestoreGame(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- char *game_id = kernel_dereference_char_pointer(s, argv[0], 0);
+ char *game_id = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
int savedir_nr = argv[1].toUint16();
debug(3, "kRestoreGame(%s,%d)", game_id, savedir_nr);
@@ -677,7 +677,7 @@ reg_t kRestoreGame(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kValidPath(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- const char *path = kernel_dereference_char_pointer(s, argv[0], 0);
+ const char *path = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
// FIXME: For now, we only accept the (fake) root dir "/" as a valid path.
s->r_acc = make_reg(0, 0 == strcmp(path, "/"));
@@ -728,7 +728,7 @@ void DirSeeker::nextFile() {
return;
}
- char *mem = kernel_dereference_char_pointer(_vm, _outbuffer, 0);
+ char *mem = kernel_dereference_char_pointer(_vm->segmentManager, _outbuffer, 0);
memset(mem, 0, 13);
// TODO: Transform the string back into a format usable by the SCI scripts.
@@ -749,7 +749,7 @@ reg_t kFileIO(EngineState *s, int funct_nr, int argc, reg_t *argv) {
switch (func_nr) {
case K_FILEIO_OPEN : {
- char *name = kernel_dereference_char_pointer(s, argv[1], 0);
+ char *name = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
int mode = argv[2].toUint16();
file_open(s, name, mode);
@@ -765,7 +765,7 @@ reg_t kFileIO(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
case K_FILEIO_READ_RAW : {
int handle = argv[1].toUint16();
- char *dest = kernel_dereference_char_pointer(s, argv[2], 0);
+ char *dest = kernel_dereference_char_pointer(s->segmentManager, argv[2], 0);
int size = argv[3].toUint16();
debug(3, "K_FILEIO_READ_RAW(%d,%d)", handle, size);
@@ -774,7 +774,7 @@ reg_t kFileIO(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
case K_FILEIO_WRITE_RAW : {
int handle = argv[1].toUint16();
- char *buf = kernel_dereference_char_pointer(s, argv[2], 0);
+ char *buf = kernel_dereference_char_pointer(s->segmentManager, argv[2], 0);
int size = argv[3].toUint16();
debug(3, "K_FILEIO_WRITE_RAW(%d,%d)", handle, size);
@@ -782,7 +782,7 @@ reg_t kFileIO(EngineState *s, int funct_nr, int argc, reg_t *argv) {
break;
}
case K_FILEIO_UNLINK : {
- char *name = kernel_dereference_char_pointer(s, argv[1], 0);
+ char *name = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
debug(3, "K_FILEIO_UNLINK(%s)", name);
Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager();
@@ -793,7 +793,7 @@ reg_t kFileIO(EngineState *s, int funct_nr, int argc, reg_t *argv) {
break;
}
case K_FILEIO_READ_STRING : {
- char *dest = kernel_dereference_char_pointer(s, argv[1], 0);
+ char *dest = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
int size = argv[2].toUint16();
int handle = argv[3].toUint16();
debug(3, "K_FILEIO_READ_STRING(%d,%d)", handle, size);
@@ -804,7 +804,7 @@ reg_t kFileIO(EngineState *s, int funct_nr, int argc, reg_t *argv) {
case K_FILEIO_WRITE_STRING : {
int handle = argv[1].toUint16();
int size = argv[3].toUint16();
- char *buf = kernel_dereference_char_pointer(s, argv[2], size);
+ char *buf = kernel_dereference_char_pointer(s->segmentManager, argv[2], size);
debug(3, "K_FILEIO_WRITE_STRING(%d,%d)", handle, size);
// FIXME: What is the difference between K_FILEIO_WRITE_STRING and
@@ -825,7 +825,7 @@ reg_t kFileIO(EngineState *s, int funct_nr, int argc, reg_t *argv) {
break;
}
case K_FILEIO_FIND_FIRST : {
- char *mask = kernel_dereference_char_pointer(s, argv[1], 0);
+ char *mask = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
reg_t buf = argv[2];
int attr = argv[3].toUint16(); // We won't use this, Win32 might, though...
debug(3, "K_FILEIO_FIND_FIRST(%s,0x%x)", mask, attr);
@@ -844,7 +844,7 @@ reg_t kFileIO(EngineState *s, int funct_nr, int argc, reg_t *argv) {
break;
}
case K_FILEIO_FILE_EXISTS : {
- char *name = kernel_dereference_char_pointer(s, argv[1], 0);
+ char *name = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
// Check for regular file
bool exists = Common::File::exists(name);
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index ab5cd57c34..18017e0d08 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -627,14 +627,14 @@ reg_t kGraph(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kTextSize(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int width, height;
- char *text = argv[1].segment ? (char *) kernel_dereference_bulk_pointer(s, argv[1], 0) : NULL;
+ char *text = argv[1].segment ? (char *) kernel_dereference_bulk_pointer(s->segmentManager, argv[1], 0) : NULL;
const char *sep = NULL;
- reg_t *dest = kernel_dereference_reg_pointer(s, argv[0], 4);
+ reg_t *dest = kernel_dereference_reg_pointer(s->segmentManager, argv[0], 4);
int maxwidth = (argc > 3) ? argv[3].toUint16() : 0;
int font_nr = argv[2].toUint16();
if ((argc > 4) && (argv[4].segment))
- sep = (const char *)kernel_dereference_bulk_pointer(s, argv[4], 0);
+ sep = (const char *)kernel_dereference_bulk_pointer(s->segmentManager, argv[4], 0);
if (maxwidth < 0)
maxwidth = 0;
@@ -689,6 +689,7 @@ reg_t kPriCoord(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
void _k_dirloop(reg_t obj, uint16 angle, EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
int view = GET_SEL32V(obj, view);
int signal = GET_SEL32V(obj, signal);
int loop;
@@ -746,9 +747,10 @@ reg_t kDirLoop(EngineState *s, int funct_nr, int argc, reg_t *argv) {
static Common::Rect nsrect_clip(EngineState *s, int y, Common::Rect retval, int priority);
static int collides_with(EngineState *s, Common::Rect area, reg_t other_obj, int use_nsrect, int view_mask, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
int other_signal = GET_SEL32V(other_obj, signal);
int other_priority = GET_SEL32V(other_obj, priority);
- int y = GET_SEL32SV(other_obj, y);
+ int y = (int16)GET_SEL32V(other_obj, y);
Common::Rect other_area;
if (use_nsrect) {
@@ -785,6 +787,7 @@ static int collides_with(EngineState *s, Common::Rect area, reg_t other_obj, int
}
reg_t kCanBeHere(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
reg_t obj = argv[0];
reg_t cliplist_ref = (argc > 1) ? argv[1] : NULL_REG;
List *cliplist = NULL;
@@ -797,10 +800,10 @@ reg_t kCanBeHere(EngineState *s, int funct_nr, int argc, reg_t *argv) {
uint16 edgehit;
uint16 illegal_bits;
- abs_zone.left = GET_SEL32SV(obj, brLeft);
- abs_zone.right = GET_SEL32SV(obj, brRight);
- abs_zone.top = GET_SEL32SV(obj, brTop);
- abs_zone.bottom = GET_SEL32SV(obj, brBottom);
+ abs_zone.left = (int16)GET_SEL32V(obj, brLeft);
+ abs_zone.right = (int16)GET_SEL32V(obj, brRight);
+ abs_zone.top = (int16)GET_SEL32V(obj, brTop);
+ abs_zone.bottom = (int16)GET_SEL32V(obj, brBottom);
zone = gfx_rect(abs_zone.left + port->zone.x, abs_zone.top + port->zone.y, abs_zone.width(), abs_zone.height());
@@ -939,6 +942,7 @@ reg_t kCelWide(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kNumLoops(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
reg_t obj = argv[0];
int view = GET_SEL32V(obj, view);
int loops_nr = gfxop_lookup_view_get_loops(s->gfx_state, view);
@@ -954,12 +958,12 @@ reg_t kNumLoops(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kNumCels(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
reg_t obj = argv[0];
int loop = GET_SEL32V(obj, loop);
int view = GET_SEL32V(obj, view);
int cel = 0xffff;
-
if (gfxop_check_cel(s->gfx_state, view, &loop, &cel)) {
// OK, this is a hack and there's a
// real function to calculate cel numbers...
@@ -1073,6 +1077,7 @@ reg_t kDrawPic(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
Common::Rect set_base(EngineState *s, reg_t object) {
+ SegManager *segManager = s->segmentManager;
int x, y, original_y, z, ystep, xsize, ysize;
int xbase, ybase, xend, yend;
int view, loop, cel;
@@ -1080,19 +1085,19 @@ Common::Rect set_base(EngineState *s, reg_t object) {
int xmod = 0, ymod = 0;
Common::Rect retval;
- x = GET_SEL32SV(object, x);
- original_y = y = GET_SEL32SV(object, y);
+ x = (int16)GET_SEL32V(object, x);
+ original_y = y = (int16)GET_SEL32V(object, y);
if (((SciEngine*)g_engine)->getKernel()->_selectorMap.z > -1)
- z = GET_SEL32SV(object, z);
+ z = (int16)GET_SEL32V(object, z);
else
z = 0;
y -= z; // Subtract z offset
- ystep = GET_SEL32SV(object, yStep);
+ ystep = (int16)GET_SEL32V(object, yStep);
- view = GET_SEL32SV(object, view);
+ view = (int16)GET_SEL32V(object, view);
oldloop = loop = sign_extend_byte(GET_SEL32V(object, loop));
oldcel = cel = sign_extend_byte(GET_SEL32V(object, cel));
@@ -1135,6 +1140,7 @@ Common::Rect set_base(EngineState *s, reg_t object) {
}
void _k_base_setter(EngineState *s, reg_t object) {
+ SegManager *segManager = s->segmentManager;
Common::Rect absrect = set_base(s, object);
if (lookup_selector(s->segmentManager, object, ((SciEngine*)g_engine)->getKernel()->_selectorMap.brLeft, NULL, NULL) != kSelectorVariable)
@@ -1211,28 +1217,29 @@ static Common::Rect calculate_nsrect(EngineState *s, int x, int y, int view, int
}
Common::Rect get_nsrect(EngineState *s, reg_t object, byte clip) {
+ SegManager *segManager = s->segmentManager;
int x, y, z;
int view, loop, cel;
Common::Rect retval;
- x = GET_SEL32SV(object, x);
- y = GET_SEL32SV(object, y);
+ x = (int16)GET_SEL32V(object, x);
+ y = (int16)GET_SEL32V(object, y);
if (((SciEngine*)g_engine)->getKernel()->_selectorMap.z > -1)
- z = GET_SEL32SV(object, z);
+ z = (int16)GET_SEL32V(object, z);
else
z = 0;
y -= z; // Subtract z offset
- view = GET_SEL32SV(object, view);
- loop = sign_extend_byte(GET_SEL32SV(object, loop));
- cel = sign_extend_byte(GET_SEL32SV(object, cel));
+ view = (int16)GET_SEL32V(object, view);
+ loop = sign_extend_byte((int16)GET_SEL32V(object, loop));
+ cel = sign_extend_byte((int16)GET_SEL32V(object, cel));
retval = calculate_nsrect(s, x, y, view, loop, cel);
if (clip) {
- int priority = GET_SEL32SV(object, priority);
+ int priority = (int16)GET_SEL32V(object, priority);
return nsrect_clip(s, y, retval, priority);
}
@@ -1240,6 +1247,7 @@ Common::Rect get_nsrect(EngineState *s, reg_t object, byte clip) {
}
static void _k_set_now_seen(EngineState *s, reg_t object) {
+ SegManager *segManager = s->segmentManager;
Common::Rect absrect = get_nsrect(s, object, 0);
if (lookup_selector(s->segmentManager, object, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsTop, NULL, NULL) != kSelectorVariable) {
@@ -1331,6 +1339,7 @@ reg_t kPalette(EngineState *s, int funct_nr, int argc, reg_t *argv) {
static void _k_draw_control(EngineState *s, reg_t obj, int inverse);
static void _k_disable_delete_for_now(EngineState *s, reg_t obj) {
+ SegManager *segManager = s->segmentManager;
reg_t text_pos = GET_SEL32(obj, text);
char *text = text_pos.isNull() ? NULL : (char *)s->segmentManager->dereference(text_pos, NULL);
int type = GET_SEL32V(obj, type);
@@ -1401,6 +1410,7 @@ void update_cursor_limits(int *display_offset, int *cursor, int max_displayed) {
}
reg_t kEditControl(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
reg_t obj = argv[0];
reg_t event = argv[1];
@@ -1575,10 +1585,11 @@ reg_t kEditControl(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
static void _k_draw_control(EngineState *s, reg_t obj, int inverse) {
- int x = GET_SEL32SV(obj, nsLeft);
- int y = GET_SEL32SV(obj, nsTop);
- int xl = GET_SEL32SV(obj, nsRight) - x;
- int yl = GET_SEL32SV(obj, nsBottom) - y;
+ SegManager *segManager = s->segmentManager;
+ int x = (int16)GET_SEL32V(obj, nsLeft);
+ int y = (int16)GET_SEL32V(obj, nsTop);
+ int xl = (int16)GET_SEL32V(obj, nsRight) - x;
+ int yl = (int16)GET_SEL32V(obj, nsBottom) - y;
rect_t area = gfx_rect(x, y, xl, yl);
int font_nr = GET_SEL32V(obj, font);
@@ -1708,7 +1719,7 @@ static void draw_obj_to_control_map(EngineState *s, GfxDynView *view) {
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);
+ reg_t* sp = view->signalp.getPointer(s->segmentManager);
if (!(sp && (sp->offset & _K_VIEW_SIG_FLAG_IGNORE_ACTOR))) {
Common::Rect abs_zone = get_nsrect(s, make_reg(view->_ID, view->_subID), 1);
draw_rect_to_control_map(s, abs_zone);
@@ -1716,6 +1727,7 @@ static void draw_obj_to_control_map(EngineState *s, GfxDynView *view) {
}
static void _k_view_list_do_postdraw(EngineState *s, GfxList *list) {
+ SegManager *segManager = s->segmentManager;
GfxDynView *widget = (GfxDynView *) list->_contents;
while (widget) {
@@ -1760,7 +1772,7 @@ static void _k_view_list_do_postdraw(EngineState *s, GfxList *list) {
fprintf(stderr, "obj %04x:%04x has pflags %x\n", PRINT_REG(obj), (widget->signal & (_K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_NO_UPDATE)));
#endif
- reg_t* sp = widget->signalp.getPointer(s);
+ reg_t* sp = widget->signalp.getPointer(s->segmentManager);
if (sp) {
*sp = make_reg(0, widget->signal & 0xffff); /* Write back signal */
}
@@ -1792,6 +1804,7 @@ int _k_view_list_dispose_loop(EngineState *s, List *list, GfxDynView *widget, in
// returns non-zero IFF views were dropped
int signal;
int dropped = 0;
+ SegManager *segManager = s->segmentManager;
_k_animate_ran = false;
@@ -1804,7 +1817,7 @@ int _k_view_list_dispose_loop(EngineState *s, List *list, GfxDynView *widget, in
return -1;
if (GFXW_IS_DYN_VIEW(widget) && (widget->_ID != GFXW_NO_ID)) {
- signal = widget->signalp.getPointer(s)->offset;
+ signal = widget->signalp.getPointer(segManager)->offset;
if (signal & _K_VIEW_SIG_FLAG_DISPOSE_ME) {
reg_t obj = make_reg(widget->_ID, widget->_subID);
reg_t under_bits = NULL_REG;
@@ -1813,7 +1826,7 @@ int _k_view_list_dispose_loop(EngineState *s, List *list, GfxDynView *widget, in
error("Non-object %04x:%04x present in view list during delete time", PRINT_REG(obj));
obj = NULL_REG;
} else {
- reg_t *ubp = widget->under_bitsp.getPointer(s);
+ reg_t *ubp = widget->under_bitsp.getPointer(segManager);
if (ubp) { // Is there a bg picture left to clean?
reg_t mem_handle = *ubp;
@@ -1827,7 +1840,7 @@ int _k_view_list_dispose_loop(EngineState *s, List *list, GfxDynView *widget, in
}
}
}
- if (is_object(s->segmentManager, obj)) {
+ if (is_object(segManager, 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) {
@@ -1835,7 +1848,7 @@ int _k_view_list_dispose_loop(EngineState *s, List *list, GfxDynView *widget, in
return dropped;
}
- reg_t *ubp = widget->under_bitsp.getPointer(s);
+ reg_t *ubp = widget->under_bitsp.getPointer(segManager);
if (ubp)
under_bits = *ubp;
@@ -1880,8 +1893,9 @@ enum {
};
static GfxDynView *_k_make_dynview_obj(EngineState *s, reg_t obj, int options, int nr, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
short oldloop, oldcel;
- int cel, loop, view_nr = GET_SEL32SV(obj, view);
+ int cel, loop, view_nr = (int16)GET_SEL32V(obj, view);
int palette;
int signal;
reg_t under_bits;
@@ -1893,12 +1907,12 @@ static GfxDynView *_k_make_dynview_obj(EngineState *s, reg_t obj, int options, i
obj = obj;
- pos.x = GET_SEL32SV(obj, x);
- pos.y = GET_SEL32SV(obj, y);
+ pos.x = (int16)GET_SEL32V(obj, x);
+ pos.y = (int16)GET_SEL32V(obj, y);
pos.y++; // magic: Sierra appears to do something like this
- z = GET_SEL32SV(obj, z);
+ z = (int16)GET_SEL32V(obj, z);
// !-- nsRect used to be checked here!
loop = oldloop = sign_extend_byte(GET_SEL32V(obj, loop));
@@ -1932,7 +1946,7 @@ static GfxDynView *_k_make_dynview_obj(EngineState *s, reg_t obj, int options, i
under_bits = NULL_REG;
debugC(2, kDebugLevelGraphics, "Object at %04x:%04x has no underBits\n", PRINT_REG(obj));
} else
- under_bits = *under_bitsp.getPointer(s);
+ under_bits = *under_bitsp.getPointer(s->segmentManager);
ObjVarRef signalp;
if (lookup_selector(s->segmentManager, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.signal, &(signalp), NULL) != kSelectorVariable) {
@@ -1940,7 +1954,7 @@ static GfxDynView *_k_make_dynview_obj(EngineState *s, reg_t obj, int options, i
signal = 0;
debugC(2, kDebugLevelGraphics, "Object at %04x:%04x has no signal selector\n", PRINT_REG(obj));
} else {
- signal = signalp.getPointer(s)->offset;
+ signal = signalp.getPointer(s->segmentManager)->offset;
debugC(2, kDebugLevelGraphics, " with signal = %04x\n", signal);
}
@@ -1963,6 +1977,7 @@ static void _k_make_view_list(EngineState *s, GfxList **widget_list, List *list,
** number of list entries in *list_nr. Calls doit for each entry if cycle is set.
** argc, argv, funct_nr should be the same as in the calling kernel function.
*/
+ SegManager *segManager = s->segmentManager;
Node *node;
int sequence_nr = 0;
GfxDynView *widget;
@@ -2015,7 +2030,7 @@ static void _k_make_view_list(EngineState *s, GfxList **widget_list, List *list,
widget = (GfxDynView *)(*widget_list)->_contents;
while (widget) { // Read back widget values
- reg_t *sp = widget->signalp.getPointer(s);
+ reg_t *sp = widget->signalp.getPointer(s->segmentManager);
if (sp)
widget->signal = sp->offset;
@@ -2024,6 +2039,7 @@ static void _k_make_view_list(EngineState *s, GfxList **widget_list, List *list,
}
static void _k_prepare_view_list(EngineState *s, GfxList *list, int options) {
+ SegManager *segManager = s->segmentManager;
GfxDynView *view = (GfxDynView *) list->_contents;
while (view) {
reg_t obj = make_reg(view->_ID, view->_subID);
@@ -2036,7 +2052,7 @@ static void _k_prepare_view_list(EngineState *s, GfxList *list, int options) {
_priority = _find_view_priority(s, _priority - 1);
if (options & _K_MAKE_VIEW_LIST_DRAW_TO_CONTROL_MAP) { // Picview
- priority = GET_SEL32SV(obj, priority);
+ priority = (int16)GET_SEL32V(obj, priority);
if (priority < 0)
priority = _priority; // Always for picviews
} else { // Dynview
@@ -2047,7 +2063,7 @@ static void _k_prepare_view_list(EngineState *s, GfxList *list, int options) {
priority = _priority;
} else // DON'T calculate the priority
- priority = GET_SEL32SV(obj, priority);
+ priority = (int16)GET_SEL32V(obj, priority);
}
view->_color.priority = priority;
@@ -2243,7 +2259,7 @@ void _k_draw_view_list(EngineState *s, GfxList *list, int flags) {
widget = gfxw_picviewize_dynview(widget);
if (GFXW_IS_DYN_VIEW(widget) && widget->_ID) {
- uint16 signal = (flags & _K_DRAW_VIEW_LIST_USE_SIGNAL) ? widget->signalp.getPointer(s)->offset : 0;
+ uint16 signal = (flags & _K_DRAW_VIEW_LIST_USE_SIGNAL) ? widget->signalp.getPointer(s->segmentManager)->offset : 0;
if (signal & _K_VIEW_SIG_FLAG_HIDDEN)
gfxw_hide_widget(widget);
@@ -2263,7 +2279,7 @@ void _k_draw_view_list(EngineState *s, GfxList *list, int flags) {
else
gfxw_show_widget(widget);
- *widget->signalp.getPointer(s) = make_reg(0, signal); // Write the changes back
+ *widget->signalp.getPointer(s->segmentManager) = make_reg(0, signal); // Write the changes back
};
} // ...if we're drawing disposeables and this one is disposeable, or if we're drawing non-
@@ -2537,7 +2553,7 @@ reg_t kNewWindow(EngineState *s, int funct_nr, int argc, reg_t *argv) {
lWhite.alpha = 0;
lWhite.priority = -1;
lWhite.control = -1;
- const char *title = argv[4 + argextra].segment ? kernel_dereference_char_pointer(s, argv[4 + argextra], 0) : NULL;
+ const char *title = argv[4 + argextra].segment ? kernel_dereference_char_pointer(s->segmentManager, argv[4 + argextra], 0) : NULL;
window = sciw_new_window(s, gfx_rect(x, y, xl, yl), s->titlebar_port->_font, fgcolor, bgcolor,
s->titlebar_port->_font, lWhite, black, title ? s->strSplit(title, NULL).c_str() : NULL, flags);
@@ -3164,7 +3180,7 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) {
if (textp.segment) {
argpt = 1;
- text = (char *)kernel_dereference_bulk_pointer(s, textp, 0);
+ text = (char *)kernel_dereference_bulk_pointer(s->segmentManager, textp, 0);
} else {
argpt = 2;
text = kernel_lookup_text(s, textp, index);
@@ -3332,7 +3348,7 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kShowMovie(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- const char *filename = kernel_dereference_char_pointer(s, argv[0], 0);
+ const char *filename = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
int delay = argv[1].toUint16(); // Time between frames in ticks
int frameNr = 0;
SeqDecoder seq;
diff --git a/engines/sci/engine/klists.cpp b/engines/sci/engine/klists.cpp
index bdf9115c84..d911b04674 100644
--- a/engines/sci/engine/klists.cpp
+++ b/engines/sci/engine/klists.cpp
@@ -425,11 +425,12 @@ int sort_temp_cmp(const void *p1, const void *p2) {
}
reg_t kSort(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
reg_t source = argv[0];
reg_t dest = argv[1];
reg_t order_func = argv[2];
- int input_size = GET_SEL32SV(source, size);
+ int input_size = (int16)GET_SEL32V(source, size);
int i;
sort_temp_t *temp_array = (sort_temp_t *)malloc(sizeof(sort_temp_t) * input_size);
diff --git a/engines/sci/engine/kmenu.cpp b/engines/sci/engine/kmenu.cpp
index c65d201b90..95ce372c5f 100644
--- a/engines/sci/engine/kmenu.cpp
+++ b/engines/sci/engine/kmenu.cpp
@@ -34,8 +34,8 @@
namespace Sci {
reg_t kAddMenu(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- char *name = kernel_dereference_char_pointer(s, argv[0], 0);
- char *contents = kernel_dereference_char_pointer(s, argv[1], 0);
+ char *name = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
+ char *contents = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
s->_menubar->addMenu(s->gfx_state, name,
contents, s->titlebar_port->_font, argv[1]);
@@ -78,7 +78,7 @@ reg_t kDrawStatus(EngineState *s, int funct_nr, int argc, reg_t *argv) {
s->status_bar_background = bgcolor;
if (text.segment) {
- const char *tmp = strdup(kernel_dereference_char_pointer(s, text, 0));
+ const char *tmp = strdup(kernel_dereference_char_pointer(s->segmentManager, text, 0));
s->_statusBarText = tmp ? tmp : "";
}
@@ -124,6 +124,7 @@ static int _menu_go_down(Menubar *menubar, int menu_nr, int item_nr) {
reg_t kMenuSelect(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
reg_t event = argv[0];
/*int pause_sound = (argc > 1) ? argv[1].toUint16() : 1;*/ /* FIXME: Do this eventually */
bool claimed = false;
diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp
index 7f6f95347b..16eb7ae7d5 100644
--- a/engines/sci/engine/kmisc.cpp
+++ b/engines/sci/engine/kmisc.cpp
@@ -195,8 +195,8 @@ reg_t kMemory(EngineState *s, int funct_nr, int argc, reg_t *argv) {
break;
case K_MEMORY_MEMCPY : {
int size = argv[3].toUint16();
- byte *dest = kernel_dereference_bulk_pointer(s, argv[1], size);
- byte *src = kernel_dereference_bulk_pointer(s, argv[2], size);
+ byte *dest = kernel_dereference_bulk_pointer(s->segmentManager, argv[1], size);
+ byte *src = kernel_dereference_bulk_pointer(s->segmentManager, argv[2], size);
if (dest && src)
memcpy(dest, src, size);
@@ -212,7 +212,7 @@ reg_t kMemory(EngineState *s, int funct_nr, int argc, reg_t *argv) {
break;
}
case K_MEMORY_PEEK : {
- byte *ref = kernel_dereference_bulk_pointer(s, argv[1], 2);
+ byte *ref = kernel_dereference_bulk_pointer(s->segmentManager, argv[1], 2);
if (!ref) {
// This occurs in KQ5CD when interacting with certain objects
@@ -226,7 +226,7 @@ reg_t kMemory(EngineState *s, int funct_nr, int argc, reg_t *argv) {
break;
}
case K_MEMORY_POKE : {
- byte *ref = kernel_dereference_bulk_pointer(s, argv[1], 2);
+ byte *ref = kernel_dereference_bulk_pointer(s->segmentManager, argv[1], 2);
if (!ref) {
warning("Attempt to poke invalid memory at %04x:%04x", PRINT_REG(argv[1]));
diff --git a/engines/sci/engine/kmovement.cpp b/engines/sci/engine/kmovement.cpp
index 2c0dd1500b..f0420b56a0 100644
--- a/engines/sci/engine/kmovement.cpp
+++ b/engines/sci/engine/kmovement.cpp
@@ -68,6 +68,7 @@ Still, what we compute in the end is of course not a real velocity anymore, but
used in an iterative stepping algorithm
*/
reg_t kSetJump(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
// Input data
reg_t object = argv[0];
int dx = argv[1].toSint16();
@@ -164,10 +165,10 @@ reg_t kSetJump(EngineState *s, int funct_nr, int argc, reg_t *argv) {
#define _K_BRESEN_AXIS_X 0
#define _K_BRESEN_AXIS_Y 1
-static void initialize_bresen(EngineState *s, int argc, reg_t *argv, reg_t mover, int step_factor, int deltax, int deltay) {
+static void initialize_bresen(SegManager *segManager, int argc, reg_t *argv, reg_t mover, int step_factor, int deltax, int deltay) {
reg_t client = GET_SEL32(mover, client);
- int stepx = GET_SEL32SV(client, xStep) * step_factor;
- int stepy = GET_SEL32SV(client, yStep) * step_factor;
+ int stepx = (int16)GET_SEL32V(client, xStep) * step_factor;
+ int stepy = (int16)GET_SEL32V(client, yStep) * step_factor;
int numsteps_x = stepx ? (abs(deltax) + stepx - 1) / stepx : 0;
int numsteps_y = stepy ? (abs(deltay) + stepy - 1) / stepy : 0;
int bdi, i1;
@@ -218,14 +219,15 @@ static void initialize_bresen(EngineState *s, int argc, reg_t *argv, reg_t mover
}
reg_t kInitBresen(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
reg_t mover = argv[0];
reg_t client = GET_SEL32(mover, client);
- int deltax = GET_SEL32SV(mover, x) - GET_SEL32SV(client, x);
- int deltay = GET_SEL32SV(mover, y) - GET_SEL32SV(client, y);
+ int deltax = (int16)GET_SEL32V(mover, x) - (int16)GET_SEL32V(client, x);
+ int deltay = (int16)GET_SEL32V(mover, y) - (int16)GET_SEL32V(client, y);
int step_factor = (argc < 1) ? argv[1].toUint16() : 1;
- initialize_bresen(s, argc, argv, mover, step_factor, deltax, deltay);
+ initialize_bresen(s->segmentManager, argc, argv, mover, step_factor, deltax, deltay);
return s->r_acc;
}
@@ -283,11 +285,12 @@ static void bresenham_autodetect(EngineState *s) {
}
reg_t kDoBresen(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
reg_t mover = argv[0];
reg_t client = GET_SEL32(mover, client);
- int x = GET_SEL32SV(client, x);
- int y = GET_SEL32SV(client, y);
+ int x = (int16)GET_SEL32V(client, x);
+ int y = (int16)GET_SEL32V(client, y);
int oldx, oldy, destx, desty, dx, dy, bdi, bi1, bi2, movcnt, bdelta, axis;
uint16 signal = GET_SEL32V(client, signal);
int completed = 0;
@@ -302,16 +305,16 @@ reg_t kDoBresen(EngineState *s, int funct_nr, int argc, reg_t *argv) {
PUT_SEL32(client, signal, make_reg(0, signal)); // This is a NOP for SCI0
oldx = x;
oldy = y;
- destx = GET_SEL32SV(mover, x);
- desty = GET_SEL32SV(mover, y);
- dx = GET_SEL32SV(mover, dx);
- dy = GET_SEL32SV(mover, dy);
- bdi = GET_SEL32SV(mover, b_di);
- bi1 = GET_SEL32SV(mover, b_i1);
- bi2 = GET_SEL32SV(mover, b_i2);
+ destx = (int16)GET_SEL32V(mover, x);
+ desty = (int16)GET_SEL32V(mover, y);
+ dx = (int16)GET_SEL32V(mover, dx);
+ dy = (int16)GET_SEL32V(mover, dy);
+ bdi = (int16)GET_SEL32V(mover, b_di);
+ bi1 = (int16)GET_SEL32V(mover, b_i1);
+ bi2 = (int16)GET_SEL32V(mover, b_i2);
movcnt = GET_SEL32V(mover, b_movCnt);
- bdelta = GET_SEL32SV(mover, b_incr);
- axis = GET_SEL32SV(mover, b_xAxis);
+ bdelta = (int16)GET_SEL32V(mover, b_incr);
+ axis = (int16)GET_SEL32V(mover, b_xAxis);
//printf("movecnt %d, move speed %d\n", movcnt, max_movcnt);
@@ -392,6 +395,7 @@ int is_heap_object(EngineState *s, reg_t pos);
extern int get_angle(int xrel, int yrel);
reg_t kDoAvoider(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
reg_t avoider = argv[0];
reg_t client, looper, mover;
int angle;
diff --git a/engines/sci/engine/kpathing.cpp b/engines/sci/engine/kpathing.cpp
index 8d6142166a..0c88f1ddd9 100644
--- a/engines/sci/engine/kpathing.cpp
+++ b/engines/sci/engine/kpathing.cpp
@@ -284,7 +284,7 @@ static Common::Point read_point(const byte *list, int is_reg_t, int offset) {
/**
* Checks whether two polygons are equal
*/
-static bool polygons_equal(EngineState *s, reg_t p1, reg_t p2) {
+static bool polygons_equal(SegManager *segManager, reg_t p1, reg_t p2) {
// Check for same type
if (GET_SEL32(p1, type).toUint16() != GET_SEL32(p2, type).toUint16())
return false;
@@ -295,8 +295,8 @@ static bool polygons_equal(EngineState *s, reg_t p1, reg_t p2) {
if (size != GET_SEL32(p2, size).toUint16())
return false;
- const byte *p1_points = kernel_dereference_bulk_pointer(s, GET_SEL32(p1, points), size * POLY_POINT_SIZE);
- const byte *p2_points = kernel_dereference_bulk_pointer(s, GET_SEL32(p2, points), size * POLY_POINT_SIZE);
+ const byte *p1_points = kernel_dereference_bulk_pointer(segManager, GET_SEL32(p1, points), size * POLY_POINT_SIZE);
+ const byte *p2_points = kernel_dereference_bulk_pointer(segManager, GET_SEL32(p2, points), size * POLY_POINT_SIZE);
bool p1_is_reg_t = polygon_is_reg_t(p1_points, size);
bool p2_is_reg_t = polygon_is_reg_t(p2_points, size);
@@ -359,7 +359,7 @@ static void draw_polygon(EngineState *s, reg_t polygon) {
int size = GET_SEL32(polygon, size).toUint16();
int type = GET_SEL32(polygon, type).toUint16();
Common::Point first, prev;
- const byte *list = kernel_dereference_bulk_pointer(s, points, size * POLY_POINT_SIZE);
+ const byte *list = kernel_dereference_bulk_pointer(s->segmentManager, points, size * POLY_POINT_SIZE);
int is_reg_t = polygon_is_reg_t(list, size);
int i;
@@ -401,12 +401,12 @@ static void draw_input(EngineState *s, reg_t poly_list, Common::Point start, Com
#endif // DEBUG_AVOIDPATH
-static void print_polygon(EngineState *s, reg_t polygon) {
+static void print_polygon(SegManager *segManager, reg_t polygon) {
reg_t points = GET_SEL32(polygon, points);
int size = GET_SEL32(polygon, size).toUint16();
int type = GET_SEL32(polygon, type).toUint16();
int i;
- const byte *point_array = kernel_dereference_bulk_pointer(s, points, size * POLY_POINT_SIZE);
+ const byte *point_array = kernel_dereference_bulk_pointer(segManager, points, size * POLY_POINT_SIZE);
int is_reg_t = polygon_is_reg_t(point_array, size);
Common::Point point;
@@ -443,7 +443,7 @@ static void print_input(EngineState *s, reg_t poly_list, Common::Point start, Co
node = lookup_node(s, list->first);
while (node) {
- print_polygon(s, node->value);
+ print_polygon(s->segmentManager, node->value);
node = lookup_node(s, node->succ);
}
}
@@ -1226,10 +1226,11 @@ static Polygon *convert_polygon(EngineState *s, reg_t polygon) {
// Parameters: (EngineState *) s: The game state
// (reg_t) polygon: The SCI polygon to convert
// Returns : (Polygon *) The converted polygon
+ SegManager *segManager = s->segmentManager;
int i;
reg_t points = GET_SEL32(polygon, points);
int size = GET_SEL32(polygon, size).toUint16();
- const byte *list = kernel_dereference_bulk_pointer(s, points, size * POLY_POINT_SIZE);
+ const byte *list = kernel_dereference_bulk_pointer(s->segmentManager, points, size * POLY_POINT_SIZE);
Polygon *poly = new Polygon(GET_SEL32(polygon, type).toUint16());
int is_reg_t = polygon_is_reg_t(list, size);
@@ -1362,6 +1363,7 @@ static PathfindingState *convert_polygon_set(EngineState *s, reg_t poly_list, Co
// (int) opt: Optimization level (0, 1 or 2)
// Returns : (PathfindingState *) On success a newly allocated pathfinding state,
// NULL otherwise
+ SegManager *segManager = s->segmentManager;
Polygon *polygon;
int err;
int count = 0;
@@ -1377,7 +1379,7 @@ static PathfindingState *convert_polygon_set(EngineState *s, reg_t poly_list, Co
// Workaround for game bugs that put a polygon in the list more than once
while (dup != node) {
- if (polygons_equal(s, node->value, dup->value)) {
+ if (polygons_equal(s->segmentManager, node->value, dup->value)) {
warning("[avoidpath] Ignoring duplicate polygon");
break;
}
diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp
index d59ed9b29d..1ecba0d529 100644
--- a/engines/sci/engine/kscripts.cpp
+++ b/engines/sci/engine/kscripts.cpp
@@ -31,16 +31,16 @@
namespace Sci {
-reg_t read_selector(EngineState *s, reg_t object, Selector selector_id, const char *file, int line) {
+reg_t read_selector(SegManager *segManager, reg_t object, Selector selector_id, const char *file, int line) {
ObjVarRef address;
- if (lookup_selector(s->segmentManager, object, selector_id, &address, NULL) != kSelectorVariable)
+ if (lookup_selector(segManager, object, selector_id, &address, NULL) != kSelectorVariable)
return NULL_REG;
else
- return *address.getPointer(s);
+ return *address.getPointer(segManager);
}
-void write_selector(EngineState *s, reg_t object, Selector selector_id, reg_t value, const char *fname, int line) {
+void write_selector(SegManager *segManager, reg_t object, Selector selector_id, reg_t value, const char *fname, int line) {
ObjVarRef address;
if ((selector_id < 0) || (selector_id > (int)((SciEngine*)g_engine)->getKernel()->getSelectorNamesSize())) {
@@ -49,11 +49,11 @@ void write_selector(EngineState *s, reg_t object, Selector selector_id, reg_t va
return;
}
- if (lookup_selector(s->segmentManager, object, selector_id, &address, NULL) != kSelectorVariable)
+ if (lookup_selector(segManager, 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
- *address.getPointer(s) = value;
+ *address.getPointer(segManager) = value;
}
int invoke_selector(EngineState *s, reg_t object, int selector_id, SelectorInvocation noinvalid, int kfunct,
@@ -221,6 +221,7 @@ reg_t kClone(EngineState *s, int funct_nr, int argc, reg_t *argv) {
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) {
+ SegManager *segManager = s->segmentManager;
reg_t victim_addr = argv[0];
Clone *victim_obj = obj_get(s->segmentManager, victim_addr);
uint16 underBits;
diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp
index 06da533003..514f063f7e 100644
--- a/engines/sci/engine/ksound.cpp
+++ b/engines/sci/engine/ksound.cpp
@@ -122,6 +122,7 @@ enum AudioSyncCommands {
static void script_set_priority(EngineState *s, reg_t obj, int priority) {
+ SegManager *segManager = s->segmentManager;
int song_nr = GET_SEL32V(obj, number);
Resource *song = s->resourceManager->findResource(ResourceId(kResourceTypeSound, song_nr), 0);
int flags = GET_SEL32V(obj, flags);
@@ -156,6 +157,7 @@ void process_sound_events(EngineState *s) { /* Get all sound events, apply their
int result;
SongHandle handle;
int cue;
+ SegManager *segManager = s->segmentManager;
if (s->resourceManager->sciVersion() > SCI_VERSION_01)
return;
@@ -205,6 +207,7 @@ void process_sound_events(EngineState *s) { /* Get all sound events, apply their
reg_t kDoSoundSci0(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
reg_t obj = (argc > 1) ? argv[1] : NULL_REG;
uint16 command = argv[0].toUint16();
SongHandle handle = FROBNICATE_HANDLE(obj);
@@ -384,6 +387,7 @@ reg_t kDoSoundSci0(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kDoSoundSci1Early(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
uint16 command = argv[0].toUint16();
reg_t obj = (argc > 1) ? argv[1] : NULL_REG;
SongHandle handle = FROBNICATE_HANDLE(obj);
@@ -674,6 +678,7 @@ reg_t kDoSoundSci1Early(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kDoSoundSci1Late(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
uint16 command = argv[0].toUint16();
reg_t obj = (argc > 1) ? argv[1] : NULL_REG;
SongHandle handle = FROBNICATE_HANDLE(obj);
@@ -1062,6 +1067,7 @@ reg_t kDoAudio(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kDoSync(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
switch (argv[0].toUint16()) {
case kSciAudioSyncStart: {
ResourceId id;
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp
index 7a936f3cb4..a177dd6aa8 100644
--- a/engines/sci/engine/kstring.cpp
+++ b/engines/sci/engine/kstring.cpp
@@ -44,7 +44,7 @@ char *kernel_lookup_text(EngineState *s, reg_t address, int index) {
Resource *textres;
if (address.segment)
- return (char *)kernel_dereference_bulk_pointer(s, address, 0);
+ return (char *)kernel_dereference_bulk_pointer(s->segmentManager, address, 0);
else {
int textlen;
int _index = index;
@@ -79,6 +79,7 @@ char *kernel_lookup_text(EngineState *s, reg_t address, int index) {
reg_t kSaid(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
reg_t heap_said_block = argv[0];
byte *said_block;
int new_lastmatch;
@@ -86,7 +87,7 @@ reg_t kSaid(EngineState *s, int funct_nr, int argc, reg_t *argv) {
if (!heap_said_block.segment)
return NULL_REG;
- said_block = (byte *) kernel_dereference_bulk_pointer(s, heap_said_block, 0);
+ said_block = (byte *) kernel_dereference_bulk_pointer(s->segmentManager, heap_said_block, 0);
if (!said_block) {
warning("Said on non-string, pointer %04x:%04x", PRINT_REG(heap_said_block));
@@ -128,6 +129,7 @@ reg_t kSaid(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kSetSynonyms(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
reg_t object = argv[0];
List *list;
Node *node;
@@ -185,8 +187,9 @@ reg_t kSetSynonyms(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kParse(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ SegManager *segManager = s->segmentManager;
reg_t stringpos = argv[0];
- char *string = kernel_dereference_char_pointer(s, stringpos, 0);
+ char *string = kernel_dereference_char_pointer(s->segmentManager, stringpos, 0);
char *error;
ResultWordList words;
reg_t event = argv[1];
@@ -239,7 +242,7 @@ reg_t kParse(EngineState *s, int funct_nr, int argc, reg_t *argv) {
s->r_acc = make_reg(0, 0);
PUT_SEL32V(event, claimed, 1);
if (error) {
- char *pbase_str = kernel_dereference_char_pointer(s, s->parser_base, 0);
+ char *pbase_str = kernel_dereference_char_pointer(s->segmentManager, s->parser_base, 0);
strcpy(pbase_str, error);
debugC(2, kDebugLevelParser, "Word unknown: %s\n", error);
/* Issue warning: */
@@ -256,7 +259,7 @@ reg_t kParse(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kStrEnd(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t address = argv[0];
- char *seeker = kernel_dereference_char_pointer(s, address, 0);
+ char *seeker = kernel_dereference_char_pointer(s->segmentManager, address, 0);
while (*seeker++)
++address.offset;
@@ -265,16 +268,16 @@ reg_t kStrEnd(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kStrCat(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- char *s1 = kernel_dereference_char_pointer(s, argv[0], 0);
- char *s2 = kernel_dereference_char_pointer(s, argv[1], 0);
+ char *s1 = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
+ char *s2 = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
strcat(s1, s2);
return argv[0];
}
reg_t kStrCmp(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- char *s1 = kernel_dereference_char_pointer(s, argv[0], 0);
- char *s2 = kernel_dereference_char_pointer(s, argv[1], 0);
+ char *s1 = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
+ char *s2 = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
if (argc > 2)
return make_reg(0, strncmp(s1, s2, argv[2].toUint16()));
@@ -284,8 +287,8 @@ reg_t kStrCmp(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kStrCpy(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- char *dest = (char *) kernel_dereference_bulk_pointer(s, argv[0], 0);
- char *src = (char *) kernel_dereference_bulk_pointer(s, argv[1], 0);
+ char *dest = (char *) kernel_dereference_bulk_pointer(s->segmentManager, argv[0], 0);
+ char *src = (char *) kernel_dereference_bulk_pointer(s->segmentManager, argv[1], 0);
if (!dest) {
warning("Attempt to strcpy TO invalid pointer %04x:%04x",
@@ -349,7 +352,7 @@ static int is_print_str(const char *str) {
reg_t kStrAt(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- byte *dest = (byte *)kernel_dereference_bulk_pointer(s, argv[0], 0);
+ byte *dest = (byte *)kernel_dereference_bulk_pointer(s->segmentManager, argv[0], 0);
reg_t *dest2;
if (!dest) {
@@ -391,7 +394,7 @@ reg_t kStrAt(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kReadNumber(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- char *source = kernel_dereference_char_pointer(s, argv[0], 0);
+ char *source = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
while (isspace(*source))
source++; /* Skip whitespace */
@@ -417,7 +420,7 @@ reg_t kReadNumber(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kFormat(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int *arguments;
reg_t dest = argv[0];
- char *target = (char *) kernel_dereference_bulk_pointer(s, dest, 0);
+ char *target = (char *) kernel_dereference_bulk_pointer(s->segmentManager, dest, 0);
reg_t position = argv[1]; /* source */
int index = argv[2].toUint16();
char *source;
@@ -630,7 +633,7 @@ reg_t kFormat(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kStrLen(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- char *str = kernel_dereference_char_pointer(s, argv[0], 0);
+ char *str = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
if (!str) {
warning("StrLen: invalid pointer %04x:%04x", PRINT_REG(argv[0]));
@@ -662,7 +665,7 @@ reg_t kGetFarText(EngineState *s, int funct_nr, int argc, reg_t *argv) {
** resource.
*/
- strcpy(kernel_dereference_char_pointer(s, argv[2], 0), seeker); /* Copy the string and get return value */
+ strcpy(kernel_dereference_char_pointer(s->segmentManager, argv[2], 0), seeker); /* Copy the string and get return value */
return argv[2];
}
@@ -737,7 +740,7 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) {
if (!bufferReg.isNull()) {
int len = str.size() + 1;
- buffer = kernel_dereference_char_pointer(s, bufferReg, len);
+ buffer = kernel_dereference_char_pointer(s->segmentManager, bufferReg, len);
if (buffer) {
strcpy(buffer, str.c_str());
@@ -745,7 +748,7 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) {
warning("Message: buffer %04x:%04x invalid or too small to hold the following text of %i bytes: '%s'", PRINT_REG(bufferReg), len, str.c_str());
// Set buffer to empty string if possible
- buffer = kernel_dereference_char_pointer(s, bufferReg, 1);
+ buffer = kernel_dereference_char_pointer(s->segmentManager, bufferReg, 1);
if (buffer)
*buffer = 0;
}
@@ -785,7 +788,7 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) {
case K_MESSAGE_LASTMESSAGE: {
MessageTuple msg = s->_msgState.getLastTuple();
int module = s->_msgState.getLastModule();
- byte *buffer = kernel_dereference_bulk_pointer(s, argv[1], 10);
+ byte *buffer = kernel_dereference_bulk_pointer(s->segmentManager, argv[1], 10);
if (buffer) {
WRITE_LE_UINT16(buffer, module);
@@ -807,18 +810,18 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kSetQuitStr(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- char *quitStr = kernel_dereference_char_pointer(s, argv[0], 0);
+ char *quitStr = kernel_dereference_char_pointer(s->segmentManager, argv[0], 0);
debug("Setting quit string to '%s'", quitStr);
return s->r_acc;
}
reg_t kStrSplit(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- const char *format = kernel_dereference_char_pointer(s, argv[1], 0);
- const char *sep = !argv[2].isNull() ? kernel_dereference_char_pointer(s, argv[2], 0) : NULL;
+ const char *format = kernel_dereference_char_pointer(s->segmentManager, argv[1], 0);
+ const char *sep = !argv[2].isNull() ? kernel_dereference_char_pointer(s->segmentManager, argv[2], 0) : NULL;
Common::String str = s->strSplit(format, sep);
// Make sure target buffer is large enough
- char *buf = kernel_dereference_char_pointer(s, argv[0], str.size() + 1);
+ char *buf = kernel_dereference_char_pointer(s->segmentManager, argv[0], str.size() + 1);
if (buf) {
strcpy(buf, str.c_str());
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index 53b4b039a3..2b9c30c1ab 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -138,6 +138,7 @@ Script *SegManager::allocateScript(int script_nr, SegmentId *seg_id) {
void SegManager::setScriptSize(Script &scr, int script_nr) {
Resource *script = _resourceManager->findResource(ResourceId(kResourceTypeScript, script_nr), 0);
Resource *heap = _resourceManager->findResource(ResourceId(kResourceTypeHeap, script_nr), 0);
+ bool oldScriptHeader = (_resourceManager->sciVersion() == SCI_VERSION_0_EARLY);
scr.script_size = script->size;
scr.heap_size = 0; // Set later
@@ -145,7 +146,7 @@ void SegManager::setScriptSize(Script &scr, int script_nr) {
if (!script || (_resourceManager->sciVersion() >= SCI_VERSION_1_1 && !heap)) {
error("SegManager::setScriptSize: failed to load %s", !script ? "script" : "heap");
}
- if (_resourceManager->sciVersion() == SCI_VERSION_0_EARLY) { // check if we got an old script header
+ if (oldScriptHeader) {
scr.buf_size = script->size + READ_LE_UINT16(script->data) * 2;
//locals_size = READ_LE_UINT16(script->data) * 2;
} else if (_resourceManager->sciVersion() < SCI_VERSION_1_1) {
@@ -390,7 +391,6 @@ void SegManager::scriptRelocate(reg_t block) {
for (k = 0; k < scr->_objects.size(); k++)
printf("- obj#%d at %04x w/ %d vars\n", k, scr->_objects[k].pos.offset, scr->_objects[k]._variables.size());
// SQ3 script 71 has broken relocation entries.
- // Since this is mainstream, we can't break out as we used to do.
printf("Trying to continue anyway...\n");
}
}
diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp
index c9ba939a4c..b02ce030b3 100644
--- a/engines/sci/engine/state.cpp
+++ b/engines/sci/engine/state.cpp
@@ -183,11 +183,11 @@ kLanguage EngineState::getLanguage() {
kLanguage lang = K_LANG_ENGLISH;
if (((SciEngine*)g_engine)->getKernel()->_selectorMap.printLang != -1) {
- EngineState *s = this;
+ SegManager *segManager = this->segmentManager;
- lang = (kLanguage)GET_SEL32V(s->game_obj, printLang);
+ lang = (kLanguage)GET_SEL32V(this->game_obj, printLang);
- if ((s->resourceManager->sciVersion() == SCI_VERSION_1_1) || (lang == K_LANG_NONE)) {
+ if ((segManager->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
@@ -220,7 +220,7 @@ kLanguage EngineState::getLanguage() {
}
// Store language in printLang selector
- PUT_SEL32V(s->game_obj, printLang, lang);
+ PUT_SEL32V(this->game_obj, printLang, lang);
}
}
@@ -228,13 +228,13 @@ kLanguage EngineState::getLanguage() {
}
Common::String EngineState::strSplit(const char *str, const char *sep) {
- EngineState *s = this;
+ SegManager *segManager = this->segmentManager;
kLanguage lang = getLanguage();
kLanguage subLang = K_LANG_NONE;
if (((SciEngine*)g_engine)->getKernel()->_selectorMap.subtitleLang != -1)
- subLang = (kLanguage)GET_SEL32V(s->game_obj, subtitleLang);
+ subLang = (kLanguage)GET_SEL32V(this->game_obj, subtitleLang);
Common::String retval = getLanguageString(str, lang);
diff --git a/engines/sci/engine/stringfrag.cpp b/engines/sci/engine/stringfrag.cpp
index 3b3c3911cf..4a2e44d2f0 100644
--- a/engines/sci/engine/stringfrag.cpp
+++ b/engines/sci/engine/stringfrag.cpp
@@ -103,7 +103,7 @@ static int internal_is_valid_stringfrag(EngineState *s, reg_t *buffer) {
}
int is_valid_stringfrag(EngineState *s, reg_t pos) {
- reg_t *buffer = kernel_dereference_reg_pointer(s, pos, 1);
+ reg_t *buffer = kernel_dereference_reg_pointer(s->segmentManager, pos, 1);
return internal_is_valid_stringfrag(s, buffer);
}
@@ -138,7 +138,7 @@ static int internal_stringfrag_length(EngineState *s, reg_t *buffer) {
}
int stringfrag_length(EngineState *s, reg_t pos) {
- reg_t *buffer = kernel_dereference_reg_pointer(s, pos, 1);
+ reg_t *buffer = kernel_dereference_reg_pointer(s->segmentManager, pos, 1);
return internal_stringfrag_length(s, buffer);
}
@@ -169,7 +169,7 @@ static void internal_stringfrag_to_ascii(EngineState *s, reg_t *buffer) {
}
void stringfrag_to_ascii(EngineState *s, reg_t pos) {
- reg_t *buffer = kernel_dereference_reg_pointer(s, pos, 1);
+ reg_t *buffer = kernel_dereference_reg_pointer(s->segmentManager, pos, 1);
internal_stringfrag_to_ascii(s, buffer);
}
@@ -191,7 +191,7 @@ static void internal_ascii_to_stringfrag(EngineState *s, reg_t *buffer) {
}
void ascii_to_stringfrag(EngineState *s, reg_t pos) {
- reg_t *buffer = kernel_dereference_reg_pointer(s, pos, 1);
+ reg_t *buffer = kernel_dereference_reg_pointer(s->segmentManager, pos, 1);
internal_ascii_to_stringfrag(s, buffer);
}
@@ -214,7 +214,7 @@ static void internal_stringfrag_append_char(EngineState *s, reg_t *buffer, unsig
}
void stringfrag_append_char(EngineState *s, reg_t pos, unsigned char c) {
- reg_t *buffer = kernel_dereference_reg_pointer(s, pos, 1);
+ reg_t *buffer = kernel_dereference_reg_pointer(s->segmentManager, pos, 1);
internal_stringfrag_append_char(s, buffer, c);
}
@@ -311,7 +311,7 @@ static void internal_stringfrag_insert_char(EngineState *s, reg_t *buffer, int p
}
void stringfrag_insert_char(EngineState *s, reg_t pos, int p, unsigned char c) {
- reg_t *buffer = kernel_dereference_reg_pointer(s, pos, 1);
+ reg_t *buffer = kernel_dereference_reg_pointer(s->segmentManager, pos, 1);
internal_stringfrag_insert_char(s, buffer, p, c);
}
@@ -343,7 +343,7 @@ static void internal_stringfrag_delete_char(EngineState *s, reg_t *buffer, int p
}
void stringfrag_delete_char(EngineState *s, reg_t pos, int p) {
- reg_t *buffer = kernel_dereference_reg_pointer(s, pos, 1);
+ reg_t *buffer = kernel_dereference_reg_pointer(s->segmentManager, pos, 1);
internal_stringfrag_delete_char(s, buffer, p);
}
@@ -360,8 +360,8 @@ void internal_stringfrag_strcpy(EngineState *s, reg_t *dest, reg_t *src) {
}
void stringfrag_strcpy(EngineState *s, reg_t dest, reg_t src) {
- reg_t *destbuf = kernel_dereference_reg_pointer(s, dest, 1);
- reg_t *srcbuf = kernel_dereference_reg_pointer(s, src, 1);
+ reg_t *destbuf = kernel_dereference_reg_pointer(s->segmentManager, dest, 1);
+ reg_t *srcbuf = kernel_dereference_reg_pointer(s->segmentManager, src, 1);
internal_stringfrag_strcpy(s, destbuf, srcbuf);
}
@@ -388,8 +388,8 @@ void internal_stringfrag_strncpy(EngineState *s, reg_t *dest, reg_t *src, int le
}
void stringfrag_strncpy(EngineState *s, reg_t dest, reg_t src, int len) {
- reg_t *destbuf = kernel_dereference_reg_pointer(s, dest, 1);
- reg_t *srcbuf = kernel_dereference_reg_pointer(s, src, 1);
+ reg_t *destbuf = kernel_dereference_reg_pointer(s->segmentManager, dest, 1);
+ reg_t *srcbuf = kernel_dereference_reg_pointer(s->segmentManager, src, 1);
internal_stringfrag_strncpy(s, destbuf, srcbuf, len);
}
@@ -416,8 +416,8 @@ int internal_stringfrag_strcmp(EngineState *s, reg_t *s1, reg_t *s2) {
}
void stringfrag_strcmp(EngineState *s, reg_t s1, reg_t s2) {
- reg_t *s1buf = kernel_dereference_reg_pointer(s, s1, 1);
- reg_t *s2buf = kernel_dereference_reg_pointer(s, s2, 1);
+ reg_t *s1buf = kernel_dereference_reg_pointer(s->segmentManager, s1, 1);
+ reg_t *s2buf = kernel_dereference_reg_pointer(s->segmentManager, s2, 1);
internal_stringfrag_strcmp(s, s1buf, s2buf);
}
@@ -449,8 +449,8 @@ int internal_stringfrag_strncmp(EngineState *s, reg_t *s1, reg_t *s2, int len) {
}
void stringfrag_strncmp(EngineState *s, reg_t s1, reg_t s2, int len) {
- reg_t *s1buf = kernel_dereference_reg_pointer(s, s1, 1);
- reg_t *s2buf = kernel_dereference_reg_pointer(s, s2, 1);
+ reg_t *s1buf = kernel_dereference_reg_pointer(s->segmentManager, s1, 1);
+ reg_t *s2buf = kernel_dereference_reg_pointer(s->segmentManager, s2, 1);
internal_stringfrag_strncmp(s, s1buf, s2buf, len);
}
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index 33682325d8..f1b6889096 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -248,10 +248,10 @@ static void _exec_varselectors(EngineState *s) {
ExecStack &xs = s->_executionStack.back();
// varselector access?
if (xs.argc) { // write?
- *(xs.getVarPointer(s)) = xs.variables_argp[1];
+ *(xs.getVarPointer(s->segmentManager)) = xs.variables_argp[1];
} else // No, read
- s->r_acc = *(xs.getVarPointer(s));
+ s->r_acc = *(xs.getVarPointer(s->segmentManager));
s->_executionStack.pop_back();
}
@@ -338,7 +338,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt
#endif
{ // Argument is supplied -> Selector should be set
if (print_send_action) {
- reg_t oldReg = *varp.getPointer(s);
+ reg_t oldReg = *varp.getPointer(s->segmentManager);
reg_t newReg = argp[1];
printf("[write to selector: change %04x:%04x to %04x:%04x]\n", PRINT_REG(oldReg), PRINT_REG(newReg));
@@ -936,7 +936,7 @@ void run_vm(EngineState *s, int restoring) {
argc += scriptState.restAdjust;
if (((SciEngine*)g_engine)->getKernel()->_kernelFuncs[opparams[0]].signature
- && !kernel_matches_signature(s,
+ && !kernel_matches_signature(s->segmentManager,
((SciEngine*)g_engine)->getKernel()->_kernelFuncs[opparams[0]].signature, argc,
scriptState.xs->sp + 1)) {
error("[VM] Invalid arguments to kernel call %x", opparams[0]);
@@ -1003,9 +1003,9 @@ void run_vm(EngineState *s, int restoring) {
if (old_xs->type == EXEC_STACK_TYPE_VARSELECTOR) {
// varselector access?
if (old_xs->argc) // write?
- *(old_xs->getVarPointer(s)) = old_xs->variables_argp[1];
+ *(old_xs->getVarPointer(s->segmentManager)) = old_xs->variables_argp[1];
else // No, read
- s->r_acc = *(old_xs->getVarPointer(s));
+ s->r_acc = *(old_xs->getVarPointer(s->segmentManager));
}
// Not reached the base, so let's do a soft return
@@ -1984,15 +1984,15 @@ void shrink_execution_stack(EngineState *s, uint size) {
s->_executionStack.erase(iter, s->_executionStack.end());
}
-reg_t* ObjVarRef::getPointer(EngineState *s) const {
- Object *o = obj_get(s->segmentManager, obj);
+reg_t* ObjVarRef::getPointer(SegManager *segManager) const {
+ Object *o = obj_get(segManager, obj);
if (!o) return 0;
return &(o->_variables[varindex]);
}
-reg_t* ExecStack::getVarPointer(EngineState *s) const {
+reg_t* ExecStack::getVarPointer(SegManager *segManager) const {
assert(type == EXEC_STACK_TYPE_VARSELECTOR);
- return addr.varp.getPointer(s);
+ return addr.varp.getPointer(segManager);
}
} // End of namespace Sci
diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h
index e6597c8f4c..e9c2924232 100644
--- a/engines/sci/engine/vm.h
+++ b/engines/sci/engine/vm.h
@@ -212,7 +212,7 @@ struct ObjVarRef {
reg_t obj;
int varindex;
- reg_t* getPointer(EngineState *s) const;
+ reg_t* getPointer(SegManager *segManager) const;
};
@@ -263,7 +263,7 @@ struct ExecStack {
int origin; // The stack frame position the call was made from, or -1 if it was the initial call
ExecStackType type;
- reg_t* getVarPointer(EngineState *s) const;
+ reg_t* getVarPointer(SegManager *segManager) const;
};