diff options
Diffstat (limited to 'engines/sci/engine')
-rw-r--r-- | engines/sci/engine/kstring.cpp | 44 | ||||
-rw-r--r-- | engines/sci/engine/message.cpp | 29 | ||||
-rw-r--r-- | engines/sci/engine/message.h | 1 |
3 files changed, 60 insertions, 14 deletions
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index b1bd5dbb65..0de81724b4 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -749,16 +749,47 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) { switch (UKPV(0)) { case 0 : + if (state.getMessage(&tuple)) { + char *buffer = NULL; + + if ((argc == 7) && (argv[6] != NULL_REG)) + buffer = kernel_dereference_char_pointer(s, argv[6], state.getLength() + 1); + + int talker = state.getTalker(); + + if (buffer) + state.getText(buffer); + // Talker id + return make_reg(0, talker); + } else { + char *buffer = NULL; + + if ((argc == 7) && (argv[6] != NULL_REG)) + buffer = kernel_dereference_char_pointer(s, argv[6], strlen(DUMMY_MESSAGE) + 1); + + if (buffer) + strcpy(buffer, DUMMY_MESSAGE); + + return NULL_REG; + } case 1 : - if (UKPV(0) == 0 ? state.getMessage(&tuple) : state.getNext()) { - char *buffer = argc == 7 ? kernel_dereference_char_pointer(s, argv[6], state.getLength() + 1) : NULL; + if (state.getNext()) { + char *buffer = NULL; + + if ((argc == 2) && (argv[1] != NULL_REG)) + buffer = kernel_dereference_char_pointer(s, argv[1], state.getLength() + 1); + + int talker = state.getTalker(); if (buffer) state.getText(buffer); // Talker id - return make_reg(0, state.getTalker()); + return make_reg(0, talker); } else { - char *buffer = argc == 7 ? kernel_dereference_char_pointer(s, argv[6], 0) : NULL; + char *buffer = NULL; + + if ((argc == 2) && (argv[1] != NULL_REG)) + buffer = kernel_dereference_char_pointer(s, argv[1], strlen(DUMMY_MESSAGE) + 1); if (buffer) strcpy(buffer, DUMMY_MESSAGE); @@ -768,7 +799,10 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) { case 2: if (state.getMessage(&tuple)) return make_reg(0, state.getLength() + 1); - else return NULL_REG; + else + return NULL_REG; + default: + warning("kMessage subfunction %i invoked (not implemented)", UKPV(0)); } return NULL_REG; diff --git a/engines/sci/engine/message.cpp b/engines/sci/engine/message.cpp index e6d2a560cc..fd924891a4 100644 --- a/engines/sci/engine/message.cpp +++ b/engines/sci/engine/message.cpp @@ -31,7 +31,8 @@ namespace Sci { void MessageState::initIndexRecordCursor() { _engineCursor.resource_beginning = _currentResource->data; _engineCursor.index_record = _indexRecords; - _engineCursor.index = 1; + _engineCursor.index = 0; + _lastMessage.seq = 0; } void MessageState::parse(IndexRecordCursor *cursor, MessageTuple *t) { @@ -48,30 +49,37 @@ void MessageState::parse(IndexRecordCursor *cursor, MessageTuple *t) { int MessageState::getMessage(MessageTuple *t) { MessageTuple looking_at; - int found = 0; initIndexRecordCursor(); - do { + while (_engineCursor.index != _recordCount) { parse(&_engineCursor, &looking_at); if (t->noun == looking_at.noun && t->verb == looking_at.verb && t->cond == looking_at.cond && t->seq == looking_at.seq) - found = 1; - } while (!found && getNext()); + return 1; + + _engineCursor.index_record += ((_version == 2101) ? 4 : 11); + _engineCursor.index++; + } // FIXME: Recursion not handled yet - return found; + return 0; } int MessageState::getNext() { if (_engineCursor.index == _recordCount) return 0; - _engineCursor.index_record += ((_version == 2101) ? 4 : 11); - _engineCursor.index ++; - return 1; + + MessageTuple mesg; + parse(&_engineCursor, &mesg); + + if (_lastMessage.seq == mesg.seq - 1) + return 1; + + return 0; } int MessageState::getTalker() { @@ -81,7 +89,10 @@ int MessageState::getTalker() { void MessageState::getText(char *buffer) { int offset = READ_LE_UINT16(_engineCursor.index_record + ((_version == 2101) ? 2 : 5)); char *stringptr = (char *)_engineCursor.resource_beginning + offset; + parse(&_engineCursor, &_lastMessage); strcpy(buffer, stringptr); + _engineCursor.index_record += ((_version == 2101) ? 4 : 11); + _engineCursor.index++; } int MessageState::getLength() { diff --git a/engines/sci/engine/message.h b/engines/sci/engine/message.h index abcef91f4d..5a8924f4b5 100644 --- a/engines/sci/engine/message.h +++ b/engines/sci/engine/message.h @@ -66,6 +66,7 @@ private: int _recordCount; byte *_indexRecords; IndexRecordCursor _engineCursor; + MessageTuple _lastMessage; int _version; }; |