aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2009-04-23 18:17:35 +0000
committerFilippos Karapetis2009-04-23 18:17:35 +0000
commitbd2c2b0e500bfa46077978d42e8a8c9e38582f4c (patch)
tree03e4b095dd9a5763929e299faf74a34ba933e501
parenta016ed90ba814541af587cb185c0844164e16941 (diff)
downloadscummvm-rg350-bd2c2b0e500bfa46077978d42e8a8c9e38582f4c.tar.gz
scummvm-rg350-bd2c2b0e500bfa46077978d42e8a8c9e38582f4c.tar.bz2
scummvm-rg350-bd2c2b0e500bfa46077978d42e8a8c9e38582f4c.zip
WIP code for kGetMessage (tested with Eco Quest 1). Currently, it doesn't always work for some reason...
svn-id: r40092
-rw-r--r--engines/sci/engine/kernel.cpp1
-rw-r--r--engines/sci/engine/kernel.h1
-rw-r--r--engines/sci/engine/kstring.cpp24
-rw-r--r--engines/sci/engine/message.cpp37
4 files changed, 45 insertions, 18 deletions
diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp
index 23bba40960..667ae917e6 100644
--- a/engines/sci/engine/kernel.cpp
+++ b/engines/sci/engine/kernel.cpp
@@ -204,6 +204,7 @@ SciKernelFunction kfunct_mappers[] = {
/*(?)*/ DEFUN("TimesCot", kTimesCot, "ii"),
/*(?)*/ DEFUN("TimesTan", kTimesTan, "ii"),
DEFUN("Message", kMessage, ".*"),
+ DEFUN("GetMessage", kGetMessage, ".*"),
DEFUN("DoAudio", kDoAudio, ".*"),
diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h
index 077191199e..e1da6a7851 100644
--- a/engines/sci/engine/kernel.h
+++ b/engines/sci/engine/kernel.h
@@ -450,6 +450,7 @@ reg_t kGetSaveDir(EngineState *s, int funct_nr, int argc, reg_t *argv);
reg_t kTextSize(EngineState *s, int funct_nr, int argc, reg_t *argv);
reg_t kIsItSkip(EngineState *s, int funct_nr, int argc, reg_t *argv);
reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv);
+reg_t kGetMessage(EngineState *s, int funct_nr, int argc, reg_t *argv);
reg_t kDoAudio(EngineState *s, int funct_nr, int argc, reg_t *argv);
reg_t k_Unknown(EngineState *s, int funct_nr, int argc, reg_t *argv);
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp
index 86d01efdc7..b991f2e1e6 100644
--- a/engines/sci/engine/kstring.cpp
+++ b/engines/sci/engine/kstring.cpp
@@ -782,4 +782,28 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) {
return NULL_REG;
}
+// FIXME: This doesn't always work, sometimes it doesn't find the requested tuple (tested with EcoQuest 1)
+reg_t kGetMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) {
+ if (!state.initialized)
+ message_state_initialize(s->resmgr, &state);
+
+ char *buffer = argc == 4 ? kernel_dereference_char_pointer(s, argv[3], 0) : NULL;
+
+ MessageTuple tuple;
+ tuple.noun = UKPV(0);
+ int module = UKPV(1);
+ tuple.verb = UKPV(2);
+ tuple.cond = 0;
+ tuple.seq = 0;
+
+ if (state.loadRes(module) && state.getSpecific(&tuple)) {
+ if (buffer)
+ state.getText(buffer, 100);
+
+ return make_reg(0, *buffer);
+ } else {
+ return NULL_REG;
+ }
+}
+
} // End of namespace Sci
diff --git a/engines/sci/engine/message.cpp b/engines/sci/engine/message.cpp
index 34754668e7..284129e365 100644
--- a/engines/sci/engine/message.cpp
+++ b/engines/sci/engine/message.cpp
@@ -28,17 +28,12 @@
namespace Sci {
-#if 0
-// Unreferenced - removed
static int get_talker_trivial(IndexRecordCursor *cursor) {
return -1;
}
-#endif
/* Version 2.101 and later code ahead */
-#if 0
-// Unreferenced - removed
static void index_record_parse_2101(IndexRecordCursor *cursor, MessageTuple *t) {
int noun = *(cursor->index_record + 0);
int verb = *(cursor->index_record + 1);
@@ -47,24 +42,17 @@ static void index_record_parse_2101(IndexRecordCursor *cursor, MessageTuple *t)
t->verb = verb;
t->cond = t->seq = 0;
}
-#endif
-#if 0
-// Unreferenced - removed
static void index_record_get_text_2101(IndexRecordCursor *cursor, char *buffer, int buffer_size) {
int offset = READ_LE_UINT16(cursor->index_record + 2);
char *stringptr = (char *)cursor->resource_beginning + offset;
strncpy(buffer, stringptr, buffer_size);
}
-#endif
-#if 0
-// Unreferenced - removed
static int header_get_index_record_count_2101(byte *header) {
return READ_LE_UINT16(header + 4);
}
-#endif
// Version 3.411 and later code ahead
@@ -175,6 +163,16 @@ int MessageState::loadRes(int module) {
return 1;
}
+static MessageHandler fixed_handler_old = {
+ 2101,
+ index_record_parse_2101,
+ get_talker_trivial,
+ index_record_get_text_2101,
+ header_get_index_record_count_2101,
+ 10, // FIXME: is this correct?
+ 11 // FIXME: is this correct?
+};
+
static MessageHandler fixed_handler = {
3411,
index_record_parse_3411,
@@ -186,20 +184,23 @@ static MessageHandler fixed_handler = {
};
void message_state_initialize(ResourceManager *resmgr, MessageState *state) {
- //Resource *tester = resmgr->findResource(kResourceTypeMessage, 0, 0);
- //int version;
+ Resource *tester = resmgr->findResource(kResourceTypeMessage, 0, 0);
+ int version;
- //if (tester == NULL)
- // return;
+ if (tester == NULL)
+ return;
- //version = READ_LE_UINT16(tester->data);
+ version = READ_LE_UINT16(tester->data);
state->initialized = 1;
state->_module = -1;
state->resmgr = resmgr;
state->current_res = NULL;
state->record_count = 0;
- state->handler = &fixed_handler;
+ if (version == 2101)
+ state->handler = &fixed_handler_old;
+ else
+ state->handler = &fixed_handler;
}
} // End of namespace Sci