diff options
author | Matthew Hoops | 2010-01-30 02:40:15 +0000 |
---|---|---|
committer | Matthew Hoops | 2010-01-30 02:40:15 +0000 |
commit | bc64dfb52e09345b149071674db480aebe456a76 (patch) | |
tree | 09ae058b63fdd655f75d07c0b2071765078e2f2a | |
parent | da46fc9b35287237ad6f9336159703e605ef565c (diff) | |
download | scummvm-rg350-bc64dfb52e09345b149071674db480aebe456a76.tar.gz scummvm-rg350-bc64dfb52e09345b149071674db480aebe456a76.tar.bz2 scummvm-rg350-bc64dfb52e09345b149071674db480aebe456a76.zip |
Implement kString(Printf) and resizing of SCI32 strings in kFormat().
svn-id: r47697
-rw-r--r-- | engines/sci/engine/kernel32.cpp | 16 | ||||
-rw-r--r-- | engines/sci/engine/kstring.cpp | 18 |
2 files changed, 26 insertions, 8 deletions
diff --git a/engines/sci/engine/kernel32.cpp b/engines/sci/engine/kernel32.cpp index 1a63eceba9..31ea2ac1df 100644 --- a/engines/sci/engine/kernel32.cpp +++ b/engines/sci/engine/kernel32.cpp @@ -612,10 +612,18 @@ reg_t kString(EngineState *s, int argc, reg_t *argv) { return GET_SEL32(s->_segMan, argv[1], data); case 10: // Stringlen return make_reg(0, s->_segMan->strlen(argv[1])); - case 11: // Printf - // TODO: Return a new formatting string - warning("kString(Printf)"); - break; + case 11: { // Printf + reg_t stringHandle; + s->_segMan->allocateString(&stringHandle); + + reg_t *adjustedArgs = new reg_t[argc]; + adjustedArgs[0] = stringHandle; + memcpy(&adjustedArgs[1], argv + 1, argc - 1); + + kFormat(s, argc, adjustedArgs); + delete[] adjustedArgs; + return stringHandle; + } case 12: // Printf Buf return kFormat(s, argc - 1, argv + 1); case 13: { // atoi diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index 89d1d0da56..f4c264b72c 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -271,10 +271,12 @@ reg_t kFormat(EngineState *s, int argc, reg_t *argv) { switch (xfer) { case 's': { /* Copy string */ reg_t reg = argv[startarg + paramindex]; - if (s->_segMan->isObject(reg)) { - Selector slc = s->_kernel->findSelector("data"); // TODO: place in selector table - reg = read_selector(s->_segMan, reg, slc); - } + +#ifdef ENABLE_SCI32 + // If the string is a string object, get to the actual string in the data selector + if (s->_segMan->isObject(reg)) + reg = GET_SEL32(s->_segMan, reg, data); +#endif Common::String tempsource = (reg == NULL_REG) ? "" : kernel_lookup_text(s, reg, arguments[paramindex + 1]); @@ -398,6 +400,14 @@ reg_t kFormat(EngineState *s, int argc, reg_t *argv) { free(arguments); *target = 0; /* Terminate string */ + +#ifdef ENABLE_SCI32 + // Resize SCI32 strings if necessary + if (getSciVersion() >= SCI_VERSION_2) { + SciString *string = s->_segMan->lookupString(dest); + string->setSize(strlen(targetbuf) + 1); + } +#endif s->_segMan->strcpy(dest, targetbuf); |