diff options
Diffstat (limited to 'engines/sci/console.cpp')
-rw-r--r-- | engines/sci/console.cpp | 309 |
1 files changed, 264 insertions, 45 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index 2c74fe4b0c..04fe0f78f4 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -53,8 +53,8 @@ #ifdef ENABLE_SCI32 #include "sci/graphics/frameout.h" #include "sci/graphics/paint32.h" +#include "sci/graphics/palette32.h" #include "video/coktel_decoder.h" -#include "sci/video/robot_decoder.h" #endif #include "common/file.h" @@ -229,6 +229,8 @@ Console::Console(SciEngine *engine) : GUI::Debugger(), registerCmd("view_listnode", WRAP_METHOD(Console, cmdViewListNode)); registerCmd("view_reference", WRAP_METHOD(Console, cmdViewReference)); registerCmd("vr", WRAP_METHOD(Console, cmdViewReference)); // alias + registerCmd("dump_reference", WRAP_METHOD(Console, cmdDumpReference)); + registerCmd("dr", WRAP_METHOD(Console, cmdDumpReference)); // alias registerCmd("view_object", WRAP_METHOD(Console, cmdViewObject)); registerCmd("vo", WRAP_METHOD(Console, cmdViewObject)); // alias registerCmd("active_object", WRAP_METHOD(Console, cmdViewActiveObject)); @@ -266,8 +268,6 @@ void Console::postEnter() { #ifdef ENABLE_SCI32 } else if (_videoFile.hasSuffix(".vmd")) { videoDecoder = new Video::AdvancedVMDDecoder(); - } else if (_videoFile.hasSuffix(".rbt")) { - videoDecoder = new RobotDecoder(_engine->getPlatform() == Common::kPlatformMacintosh); } else if (_videoFile.hasSuffix(".duk")) { duckMode = true; videoDecoder = new Video::AVIDecoder(); @@ -449,6 +449,7 @@ bool Console::cmdHelp(int argc, const char **argv) { debugPrintf(" value_type - Determines the type of a value\n"); debugPrintf(" view_listnode - Examines the list node at the given address\n"); debugPrintf(" view_reference / vr - Examines an arbitrary reference\n"); + debugPrintf(" dump_reference / dr - Dumps an arbitrary reference to disk\n"); debugPrintf(" view_object / vo - Examines the object at the given address\n"); debugPrintf(" active_object - Shows information on the currently active object or class\n"); debugPrintf(" acc_object - Shows information on the object or class at the address indexed by the accumulator\n"); @@ -489,6 +490,7 @@ bool Console::cmdGetVersion(int argc, const char **argv) { debugPrintf("Lofs type: %s\n", getSciVersionDesc(_engine->_features->detectLofsType())); debugPrintf("Move count type: %s\n", (_engine->_features->handleMoveCount()) ? "increment" : "ignore"); debugPrintf("SetCursor type: %s\n", getSciVersionDesc(_engine->_features->detectSetCursorType())); + debugPrintf("PseudoMouse ability: %s\n", _engine->_features->detectPseudoMouseAbility() == kPseudoMouseAbilityTrue ? "yes" : "no"); #ifdef ENABLE_SCI32 if ((getSciVersion() >= SCI_VERSION_2_1_EARLY) && (getSciVersion() <= SCI_VERSION_2_1_LATE)) debugPrintf("SCI2.1 kernel table: %s\n", (_engine->_features->detectSci21KernelType() == SCI_VERSION_2) ? "modified SCI2 (old)" : "SCI2.1 (new)"); @@ -497,8 +499,10 @@ bool Console::cmdGetVersion(int argc, const char **argv) { if (getSciVersion() <= SCI_VERSION_1_1) { debugPrintf("kAnimate fastCast enabled: %s\n", g_sci->_gfxAnimate->isFastCastEnabled() ? "yes" : "no"); } - debugPrintf("Uses palette merging: %s\n", g_sci->_gfxPalette16->isMerging() ? "yes" : "no"); - debugPrintf("Uses 16 bit color matching: %s\n", g_sci->_gfxPalette16->isUsing16bitColorMatch() ? "yes" : "no"); + if (getSciVersion() < SCI_VERSION_2) { + debugPrintf("Uses palette merging: %s\n", g_sci->_gfxPalette16->isMerging() ? "yes" : "no"); + debugPrintf("Uses 16 bit color matching: %s\n", g_sci->_gfxPalette16->isUsing16bitColorMatch() ? "yes" : "no"); + } debugPrintf("Resource volume version: %s\n", g_sci->getResMan()->getVolVersionDesc()); debugPrintf("Resource map version: %s\n", g_sci->getResMan()->getMapVersionDesc()); debugPrintf("Contains selector vocabulary (vocab.997): %s\n", hasVocab997 ? "yes" : "no"); @@ -675,7 +679,7 @@ bool Console::cmdRegisters(int argc, const char **argv) { bool Console::parseResourceNumber36(const char *userParameter, uint16 &resourceNumber, uint32 &resourceTuple) { int userParameterLen = strlen(userParameter); - + if (userParameterLen != 10) { debugPrintf("Audio36/Sync36 resource numbers must be specified as RRRNNVVCCS\n"); debugPrintf("where RRR is the resource number/map\n"); @@ -760,7 +764,7 @@ void Console::cmdDiskDumpWorker(ResourceType resourceType, int resourceNumber, u ResourceId resourceId; Resource *resource = NULL; char outFileName[50]; - + switch (resourceType) { case kResourceTypeAudio36: case kResourceTypeSync36: { @@ -877,7 +881,7 @@ bool Console::cmdList(int argc, const char **argv) { currentMap = map; displayCount = 0; } - + if (displayCount % 3 == 0) debugPrintf(" "); @@ -1620,7 +1624,7 @@ bool Console::cmdParserNodes(int argc, const char **argv) { bool Console::cmdSetPalette(int argc, const char **argv) { if (argc < 2) { - debugPrintf("Sets a palette resource\n"); + debugPrintf("Sets a palette resource (SCI16)\n"); debugPrintf("Usage: %s <resourceId>\n", argv[0]); debugPrintf("where <resourceId> is the number of the palette resource to set\n"); return true; @@ -1628,6 +1632,13 @@ bool Console::cmdSetPalette(int argc, const char **argv) { uint16 resourceId = atoi(argv[1]); +#ifdef ENABLE_SCI32 + if (getSciVersion() >= SCI_VERSION_2) { + debugPrintf("This SCI version does not support this command\n"); + return true; + } +#endif + _engine->_gfxPalette16->kernelSetFromResource(resourceId, true); return true; } @@ -2068,8 +2079,8 @@ bool Console::cmdPrintSegmentTable(int argc, const char **argv) { debugPrintf("A SCI32 arrays (%d)", (*(ArrayTable *)mobj).entries_used); break; - case SEG_TYPE_STRING: - debugPrintf("T SCI32 strings (%d)", (*(StringTable *)mobj).entries_used); + case SEG_TYPE_BITMAP: + debugPrintf("T SCI32 bitmaps (%d)", (*(BitmapTable *)mobj).entries_used); break; #endif @@ -2168,7 +2179,7 @@ bool Console::segmentInfo(int nr) { for (uint i = 0; i < lt.size(); i++) if (lt.isValidEntry(i)) { debugPrintf(" [%04x]: ", i); - printList(<[i]); + printList(lt[i]); } } break; @@ -2199,12 +2210,12 @@ bool Console::segmentInfo(int nr) { break; #ifdef ENABLE_SCI32 - case SEG_TYPE_STRING: - debugPrintf("SCI32 strings\n"); - break; case SEG_TYPE_ARRAY: debugPrintf("SCI32 arrays\n"); break; + case SEG_TYPE_BITMAP: + debugPrintf("SCI32 bitmaps\n"); + break; #endif default : @@ -2772,16 +2783,8 @@ bool Console::cmdViewReference(int argc, const char **argv) { switch (type) { case 0: break; - case SIG_TYPE_LIST: { - List *list = _engine->_gamestate->_segMan->lookupList(reg); - - debugPrintf("list\n"); - - if (list) - printList(list); - else - debugPrintf("Invalid list.\n"); - } + case SIG_TYPE_LIST: + printList(reg); break; case SIG_TYPE_NODE: debugPrintf("list node\n"); @@ -2794,16 +2797,12 @@ bool Console::cmdViewReference(int argc, const char **argv) { case SIG_TYPE_REFERENCE: { switch (_engine->_gamestate->_segMan->getSegmentType(reg.getSegment())) { #ifdef ENABLE_SCI32 - case SEG_TYPE_STRING: { - debugPrintf("SCI32 string\n"); - const SciString *str = _engine->_gamestate->_segMan->lookupString(reg); - Common::hexdump((const byte *) str->getRawData(), str->getSize(), 16, 0); + case SEG_TYPE_ARRAY: { + printArray(reg); break; } - case SEG_TYPE_ARRAY: { - debugPrintf("SCI32 array:\n"); - const SciArray<reg_t> *array = _engine->_gamestate->_segMan->lookupArray(reg); - hexDumpReg(array->getRawData(), array->getSize(), 4, 0, true); + case SEG_TYPE_BITMAP: { + printBitmap(reg); break; } #endif @@ -2848,6 +2847,125 @@ bool Console::cmdViewReference(int argc, const char **argv) { return true; } +bool Console::cmdDumpReference(int argc, const char **argv) { + if (argc < 2) { + debugPrintf("Dumps an arbitrary reference to disk.\n"); + debugPrintf("Usage: %s <start address> [<end address>]\n", argv[0]); + debugPrintf("Where <start address> is the starting address to dump\n"); + debugPrintf("<end address>, if provided, is the address where the dump ends\n"); + debugPrintf("Check the \"addresses\" command on how to use addresses\n"); + return true; + } + + reg_t reg = NULL_REG; + reg_t reg_end = NULL_REG; + + if (parse_reg_t(_engine->_gamestate, argv[1], ®, false)) { + debugPrintf("Invalid address passed.\n"); + debugPrintf("Check the \"addresses\" command on how to use addresses\n"); + return true; + } + + if (argc > 2) { + if (parse_reg_t(_engine->_gamestate, argv[2], ®_end, false)) { + debugPrintf("Invalid address passed.\n"); + debugPrintf("Check the \"addresses\" command on how to use addresses\n"); + return true; + } + } + + if (reg.getSegment() == 0 && reg.getOffset() == 0) { + debugPrintf("Register is null.\n"); + return true; + } + + if (g_sci->getKernel()->findRegType(reg) != SIG_TYPE_REFERENCE) { + debugPrintf("%04x:%04x is not a reference\n", PRINT_REG(reg)); + return true; + } + + if (reg_end.getSegment() != reg.getSegment() && reg_end != NULL_REG) { + debugPrintf("Ending segment different from starting segment. Assuming no bound on dump.\n"); + reg_end = NULL_REG; + } + + Common::DumpFile out; + Common::String outFileName; + uint32 bytesWritten; + + switch (_engine->_gamestate->_segMan->getSegmentType(reg.getSegment())) { +#ifdef ENABLE_SCI32 + case SEG_TYPE_BITMAP: { + outFileName = Common::String::format("%04x_%04x.tga", PRINT_REG(reg)); + out.open(outFileName); + SciBitmap &bitmap = *_engine->_gamestate->_segMan->lookupBitmap(reg); + const Color *color = g_sci->_gfxPalette32->getCurrentPalette().colors; + const uint16 numColors = ARRAYSIZE(g_sci->_gfxPalette32->getCurrentPalette().colors); + + out.writeByte(0); // image id length + out.writeByte(1); // color map type (present) + out.writeByte(1); // image type (uncompressed color-mapped) + out.writeSint16LE(0); // index of first color map entry + out.writeSint16LE(numColors); // number of color map entries + out.writeByte(24); // number of bits per color entry (RGB24) + out.writeSint16LE(0); // bottom-left x-origin + out.writeSint16LE(bitmap.getHeight() - 1); // bottom-left y-origin + out.writeSint16LE(bitmap.getWidth()); // width + out.writeSint16LE(bitmap.getHeight()); // height + out.writeByte(8); // bits per pixel + out.writeByte(1 << 5); // origin of pixel data (top-left) + + bytesWritten = 18; + + for (int i = 0; i < numColors; ++i) { + out.writeByte(color->b); + out.writeByte(color->g); + out.writeByte(color->r); + ++color; + } + + bytesWritten += numColors * 3; + bytesWritten += out.write(bitmap.getPixels(), bitmap.getWidth() * bitmap.getHeight()); + break; + } +#endif + + default: { + const SegmentRef block = _engine->_gamestate->_segMan->dereference(reg); + uint32 size = block.maxSize; + + if (size == 0) { + debugPrintf("Size of reference is zero.\n"); + return true; + } + + if (reg_end.getSegment() != 0 && (size < reg_end.getOffset() - reg.getOffset())) { + debugPrintf("Block end out of bounds (size %d). Resetting.\n", size); + reg_end = NULL_REG; + } + + if (reg_end.getSegment() != 0 && (size >= reg_end.getOffset() - reg.getOffset())) { + size = reg_end.getOffset() - reg.getOffset(); + } + + if (reg_end.getSegment() != 0) { + debugPrintf("Block size less than or equal to %d\n", size); + } + + outFileName = Common::String::format("%04x_%04x.dmp", PRINT_REG(reg)); + out.open(outFileName); + bytesWritten = out.write(block.raw, size); + break; + } + } + + out.finalize(); + out.close(); + + debugPrintf("Wrote %u bytes to %s\n", bytesWritten, outFileName.c_str()); + return true; +} + bool Console::cmdViewObject(int argc, const char **argv) { if (argc != 2) { debugPrintf("Examines the object at the given address.\n"); @@ -2899,7 +3017,7 @@ bool Console::cmdScriptObjects(int argc, const char **argv) { debugPrintf("<script number> may be * to show objects inside all loaded scripts\n"); return true; } - + if (strcmp(argv[1], "*") == 0) { // get said-strings of all currently loaded scripts curScriptNr = -1; @@ -2921,7 +3039,7 @@ bool Console::cmdScriptStrings(int argc, const char **argv) { debugPrintf("<script number> may be * to show strings inside all loaded scripts\n"); return true; } - + if (strcmp(argv[1], "*") == 0) { // get strings of all currently loaded scripts curScriptNr = -1; @@ -2943,7 +3061,7 @@ bool Console::cmdScriptSaid(int argc, const char **argv) { debugPrintf("<script number> may be * to show said-strings inside all loaded scripts\n"); return true; } - + if (strcmp(argv[1], "*") == 0) { // get said-strings of all currently loaded scripts curScriptNr = -1; @@ -3758,7 +3876,7 @@ bool Console::cmdBreakpointKernel(int argc, const char **argv) { bool Console::cmdBreakpointFunction(int argc, const char **argv) { if (argc != 3) { debugPrintf("Sets a breakpoint on the execution of the specified exported function.\n"); - debugPrintf("Usage: %s <script number> <export number\n", argv[0]); + debugPrintf("Usage: %s <script number> <export number>\n", argv[0]); return true; } @@ -4353,8 +4471,28 @@ void Console::printBasicVarInfo(reg_t variable) { debugPrintf(" IS INVALID!"); } -void Console::printList(List *list) { - reg_t pos = list->first; +void Console::printList(reg_t reg) { + SegmentObj *mobj = _engine->_gamestate->_segMan->getSegment(reg.getSegment(), SEG_TYPE_LISTS); + + if (!mobj) { + debugPrintf("list:\nCould not find list segment.\n"); + return; + } + + ListTable *table = static_cast<ListTable *>(mobj); + + if (!table->isValidEntry(reg.getOffset())) { + debugPrintf("list:\nAddress does not contain a valid list.\n"); + return; + } + + const List &list = table->at(reg.getOffset()); + debugPrintf("list:\n"); + printList(list); +} + +void Console::printList(const List &list) { + reg_t pos = list.first; reg_t my_prev = NULL_REG; debugPrintf("\t<\n"); @@ -4364,8 +4502,7 @@ void Console::printList(List *list) { NodeTable *nt = (NodeTable *)_engine->_gamestate->_segMan->getSegment(pos.getSegment(), SEG_TYPE_NODES); if (!nt || !nt->isValidEntry(pos.getOffset())) { - debugPrintf(" WARNING: %04x:%04x: Doesn't contain list node!\n", - PRINT_REG(pos)); + debugPrintf(" WARNING: %04x:%04x: Doesn't contain list node!\n", PRINT_REG(pos)); return; } @@ -4374,16 +4511,15 @@ void Console::printList(List *list) { debugPrintf("\t%04x:%04x : %04x:%04x -> %04x:%04x\n", PRINT_REG(pos), PRINT_REG(node->key), PRINT_REG(node->value)); if (my_prev != node->pred) - debugPrintf(" WARNING: current node gives %04x:%04x as predecessor!\n", - PRINT_REG(node->pred)); + debugPrintf(" WARNING: current node gives %04x:%04x as predecessor!\n", PRINT_REG(node->pred)); my_prev = pos; pos = node->succ; } - if (my_prev != list->last) + if (my_prev != list.last) debugPrintf(" WARNING: Last node was expected to be %04x:%04x, was %04x:%04x!\n", - PRINT_REG(list->last), PRINT_REG(my_prev)); + PRINT_REG(list.last), PRINT_REG(my_prev)); debugPrintf("\t>\n"); } @@ -4427,6 +4563,89 @@ int Console::printNode(reg_t addr) { return 0; } +#ifdef ENABLE_SCI32 +void Console::printArray(reg_t reg) { + SegmentObj *mobj = _engine->_gamestate->_segMan->getSegment(reg.getSegment(), SEG_TYPE_ARRAY); + + if (!mobj) { + debugPrintf("SCI32 array:\nCould not find array segment.\n"); + return; + } + + ArrayTable *table = static_cast<ArrayTable *>(mobj); + + if (!table->isValidEntry(reg.getOffset())) { + debugPrintf("SCI32 array:\nAddress does not contain a valid array.\n"); + return; + } + + const SciArray &array = table->at(reg.getOffset()); + + const char *arrayType; + switch (array.getType()) { + case kArrayTypeID: + arrayType = "reg_t"; + break; + case kArrayTypeByte: + arrayType = "byte"; + break; + case kArrayTypeInt16: + arrayType = "int16 (as reg_t)"; + break; + case kArrayTypeString: + arrayType = "string"; + break; + default: + arrayType = "invalid"; + break; + } + debugPrintf("SCI32 %s array (%u entries):\n", arrayType, array.size()); + switch (array.getType()) { + case kArrayTypeInt16: + case kArrayTypeID: { + hexDumpReg((const reg_t *)array.getRawData(), array.size(), 4, 0, true); + break; + } + case kArrayTypeByte: + case kArrayTypeString: { + Common::hexdump((const byte *)array.getRawData(), array.size(), 16, 0); + break; + } + default: + break; + } +} + +void Console::printBitmap(reg_t reg) { + SegmentObj *mobj = _engine->_gamestate->_segMan->getSegment(reg.getSegment(), SEG_TYPE_BITMAP); + + if (!mobj) { + debugPrintf("SCI32 bitmap:\nCould not find bitmap segment.\n"); + return; + } + + BitmapTable *table = static_cast<BitmapTable *>(mobj); + + if (!table->isValidEntry(reg.getOffset())) { + debugPrintf("SCI32 bitmap:\nAddress does not contain a valid bitmap.\n"); + return; + } + + const SciBitmap &bitmap = table->at(reg.getOffset()); + + debugPrintf("SCI32 bitmap (%dx%d; res %dx%d; origin %dx%d; skip color %u; %s; %s):\n", + bitmap.getWidth(), bitmap.getHeight(), + bitmap.getXResolution(), bitmap.getYResolution(), + bitmap.getOrigin().x, bitmap.getOrigin().y, + bitmap.getSkipColor(), + bitmap.getRemap() ? "remap" : "no remap", + bitmap.getShouldGC() ? "GC" : "no GC"); + + Common::hexdump((const byte *) bitmap.getRawData(), bitmap.getRawSize(), 16, 0); +} + +#endif + int Console::printObject(reg_t pos) { EngineState *s = _engine->_gamestate; // for the several defines in this function const Object *obj = s->_segMan->getObject(pos); |