Logo Search packages:      
Sourcecode: scummvm version File versions  Download package


/* ScummVM - Graphic Adventure Engine
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-0-11-1/engines/sky/debug.cpp $
 * $Id: debug.cpp 30944 2008-02-23 22:50:18Z sev $

#include "common/endian.h"
#include "common/util.h"

#include "sky/debug.h"
#include "sky/grid.h"
#include "sky/logic.h"
#include "sky/mouse.h"
#include "sky/screen.h"
#include "sky/sky.h"
#include "sky/struc.h"
#include "sky/compact.h"

namespace Sky {

static const char *logic_table_names[] = {

static const char opcode_par[] = {

static const char *opcodes[] = {

static const char *mcodes[] = {

static const char *scriptVars[] = {

void Debug::logic(uint32 logic) {
      debug(6, "LOGIC: %s", logic_table_names[logic]);

void Debug::script(uint32 command, uint16 *scriptData) {
      debug(6, "SCRIPT: %s", opcodes[command]);
      if (command == 0 || command == 6)
            debug(6, " %s", scriptVars[READ_LE_UINT16(scriptData)/4]);
      else {
            int i;
            for (i = 0; i < opcode_par[command]; i++) {
                  debug(6, " %d", READ_LE_UINT16(scriptData + i));
      debug(6, " ");    // Print an empty line as separator

void Debug::mcode(uint32 mcode, uint32 a, uint32 b, uint32 c) {
      debug(6, "MCODE: %s(%d, %d, %d)", mcodes[mcode], a, b, c);

Debugger::Debugger(Logic *logic, Mouse *mouse, Screen *screen, SkyCompact *skyCompact)
: GUI::Debugger(), _logic(logic), _mouse(mouse), _screen(screen), _skyCompact(skyCompact), _showGrid(false) {
      DCmd_Register("info",       WRAP_METHOD(Debugger, Cmd_Info));
      DCmd_Register("showgrid",   WRAP_METHOD(Debugger, Cmd_ShowGrid));
      DCmd_Register("reloadgrid", WRAP_METHOD(Debugger, Cmd_ReloadGrid));
      DCmd_Register("compact",    WRAP_METHOD(Debugger, Cmd_ShowCompact));
      DCmd_Register("logiccmd",   WRAP_METHOD(Debugger, Cmd_LogicCommand));
      DCmd_Register("scriptvar",  WRAP_METHOD(Debugger, Cmd_ScriptVar));
      DCmd_Register("section",    WRAP_METHOD(Debugger, Cmd_Section));
      DCmd_Register("logiclist",  WRAP_METHOD(Debugger, Cmd_LogicList));

Debugger::~Debugger() {} // we need this here for __SYMBIAN32__

void Debugger::preEnter() {


void Debugger::postEnter() {

bool Debugger::Cmd_ShowGrid(int argc, const char **argv) {
      _showGrid = !_showGrid;
      DebugPrintf("Show grid: %s\n", _showGrid ? "On" : "Off");
      if (!_showGrid)   _screen->forceRefresh();
      return true;

bool Debugger::Cmd_ReloadGrid(int argc, const char **argv) {
      DebugPrintf("Grid reloaded\n");
      return true;

static const char *logicTypes[] = {

static const char *noYes[] = { "no", "yes" };

void Debugger::dumpCompact(uint16 cptId) {
      uint16 type, size;
      char name[256];
      Compact *cpt = _skyCompact->fetchCptInfo(cptId, &size, &type, name);

      if (type == COMPACT) {
            DebugPrintf("Compact %s: id = %04X, section %d, id %d\n", name, cptId, cptId >> 12, cptId & 0xFFF);
            DebugPrintf("logic      : %04X: %s\n", cpt->logic, (cpt->logic <= 16) ? logicTypes[cpt->logic] : "unknown");
            DebugPrintf("status     : %04X\n", cpt->status);
            DebugPrintf("           : background  : %s\n", noYes[(cpt->status &  ST_BACKGROUND) >> 0]);
            DebugPrintf("           : foreground  : %s\n", noYes[(cpt->status &  ST_FOREGROUND) >> 1]);
            DebugPrintf("           : sort list   : %s\n", noYes[(cpt->status &        ST_SORT) >> 2]);
            DebugPrintf("           : recreate    : %s\n", noYes[(cpt->status &    ST_RECREATE) >> 3]);
            DebugPrintf("           : mouse       : %s\n", noYes[(cpt->status &       ST_MOUSE) >> 4]);
            DebugPrintf("           : collision   : %s\n", noYes[(cpt->status &   ST_COLLISION) >> 5]);
            DebugPrintf("           : logic       : %s\n", noYes[(cpt->status &       ST_LOGIC) >> 6]);
            DebugPrintf("           : on grid     : %s\n", noYes[(cpt->status &   ST_GRID_PLOT) >> 7]);
            DebugPrintf("           : ar priority : %s\n", noYes[(cpt->status & ST_AR_PRIORITY) >> 8]);
            DebugPrintf("sync       : %04X\n", cpt->sync);
            DebugPrintf("screen     : %d\n", cpt->screen);
            _skyCompact->fetchCptInfo(cpt->place, NULL, NULL, name);
            DebugPrintf("place      : %04X: %s\n", cpt->place, name);
            _skyCompact->fetchCptInfo(cpt->getToTableId, NULL, NULL, name);
            DebugPrintf("get to tab : %04X: %s\n", cpt->getToTableId, name);
            DebugPrintf("x/y        : %d/%d\n", cpt->xcood, cpt->ycood);
      } else {
            DebugPrintf("Can't dump binary data\n");

bool Debugger::Cmd_ShowCompact(int argc, const char **argv) {
      if (argc < 2) {
            DebugPrintf("Example: \"%s foster\" dumps compact \"foster\"\n", argv[0]);
            DebugPrintf("Example: \"%s list 1\" lists all compacts from section 1\n", argv[0]);
            DebugPrintf("Example: \"%s list 1 all\" lists all entities from section 1\n", argv[0]);
            return true;

      if (0 == strcmp(argv[1], "list")) {
            bool showAll = false;
            int sectionNumber = -1;
            if (argc >= 3) {
                  sectionNumber = atoi(argv[2]);
                  if (sectionNumber >= _skyCompact->giveNumDataLists()) {
                        DebugPrintf("Section number %d does not exist\n", sectionNumber);
                        return true;
                  if ((argc == 4) && (scumm_stricmp(argv[3], "all") == 0))
                        showAll = true;
            for (int sec = 0; sec < _skyCompact->giveNumDataLists(); sec++) {
                  if ((sectionNumber == -1) || (sectionNumber == sec)) {
                        DebugPrintf("Compacts in section %d:\n", sec);
                        if (showAll) {
                              char line[256];
                              char *linePos = line;
                              for (int cpt = 0; cpt < _skyCompact->giveDataListLen(sec); cpt++) {
                                    if (cpt != 0) {
                                          if ((cpt % 3) == 0) {
                                                DebugPrintf("%s\n", line);
                                                linePos = line;
                                          } else
                                                linePos += sprintf(linePos, ", ");
                                    uint16 cptId = (uint16)((sec << 12) | cpt);
                                    uint16 type, size;
                                    char name[256];
                                    _skyCompact->fetchCptInfo(cptId, &size, &type, name);
                                    linePos += sprintf(linePos, "%04X: %10s %22s", cptId, _skyCompact->nameForType(type), name);
                              if (linePos != line)
                                    DebugPrintf("%s\n", line);
                        } else {
                              for (int cpt = 0; cpt < _skyCompact->giveDataListLen(sec); cpt++) {
                                    uint16 cptId = (uint16)((sec << 12) | cpt);
                                    uint16 type, size;
                                    char name[256];
                                    _skyCompact->fetchCptInfo(cptId, &size, &type, name);
                                    if (type == COMPACT)
                                          DebugPrintf("%04X: %s\n", cptId, name);
      } else {
            uint16 cptId = _skyCompact->findCptId(argv[1]);
            if (cptId == 0)
                  DebugPrintf("Unknown compact: '%s'\n", argv[1]);
      return true;

bool Debugger::Cmd_LogicCommand(int argc, const char **argv) {
      if (argc < 2) {
            DebugPrintf("Example: %s fn_printf 42\n", argv[0]);
            return true;

      int numMCodes = ARRAYSIZE(mcodes);

      if (0 == strcmp(argv[1], "list")) {
            for (int i = 0; i < numMCodes; ++i) {
                  DebugPrintf("%s\n", mcodes[i]);
            return true;

      uint32 arg1 = 0, arg2 = 0, arg3 = 0;

      switch (argc) {
            case  5:
                  arg3 = atoi(argv[4]);
            case  4:
                  arg2 = atoi(argv[3]);
            case  3:
                  arg1 = atoi(argv[2]);

      for (int i = 0; i < numMCodes; ++i) {
            if (0 == strcmp(mcodes[i], argv[1])) {
                  _logic->fnExec(i, arg1, arg2, arg3);
                  return true;

      DebugPrintf("Unknown function: '%s'\n", argv[1]);

      return true;

bool Debugger::Cmd_Info(int argc, const char **argv) {
      DebugPrintf("Beneath a Steel Sky version: 0.0%d\n", SkyEngine::_systemVars.gameVersion);
      DebugPrintf("Speech: %s\n", (SkyEngine::_systemVars.systemFlags & SF_ALLOW_SPEECH) ? "on" : "off");
      DebugPrintf("Text  : %s\n", (SkyEngine::_systemVars.systemFlags & SF_ALLOW_TEXT) ? "on" : "off");
      return true;

bool Debugger::Cmd_ScriptVar(int argc, const char **argv) {
      if (argc < 2) {
            DebugPrintf("Example: %s lamb_friend <value>\n", argv[0]);
            return true;

      int numScriptVars = ARRAYSIZE(scriptVars);

      if (0 == strcmp(argv[1], "list")) {
            for (int i = 0; i < numScriptVars; ++i) {
                  DebugPrintf("%s\n", scriptVars[i]);
            return true;

      for (int i = 0; i < numScriptVars; ++i) {
            if (0 == strcmp(scriptVars[i], argv[1])) {
                  if (argc == 3) {
                        Logic::_scriptVariables[i] = atoi(argv[2]);
                  DebugPrintf("%s = %d\n", argv[1], Logic::_scriptVariables[i]);

                  return true;

      DebugPrintf("Unknown ScriptVar: '%s'\n", argv[1]);

      return true;

bool Debugger::Cmd_Section(int argc, const char **argv) {
      if (argc < 2) {
            DebugPrintf("Example: %s 4\n", argv[0]);
            return true;

      const int baseId[] = { START_ONE, START_S6, START_29, START_SC31, START_SC66, START_SC90, START_SC81 };
      int section = atoi(argv[1]);

      if (section >= 0 && section <= 6) {
            _logic->fnEnterSection(section == 6 ? 4 : section, 0, 0);
            _logic->fnAssignBase(ID_FOSTER, baseId[section], 0);
            _skyCompact->fetchCpt(ID_FOSTER)->megaSet = 0;
      } else {
            DebugPrintf("Unknown section '%s'\n", argv[1]);

      return true;

bool Debugger::Cmd_LogicList(int argc, const char **argv) {
      if (argc != 1)
            DebugPrintf("%s does not expect any parameters\n", argv[0]);

      char cptName[256];
      uint16 numElems, type;
      uint16 *logicList = (uint16 *)_skyCompact->fetchCptInfo(Logic::_scriptVariables[LOGIC_LIST_NO], &numElems, &type, cptName);
      DebugPrintf("Current LogicList: %04X (%s)\n", Logic::_scriptVariables[LOGIC_LIST_NO], cptName);
      while (*logicList != 0) {
            if (*logicList == 0xFFFF) {
                  uint16 newList = logicList[1];
                  logicList = (uint16 *)_skyCompact->fetchCptInfo(newList, &numElems, &type, cptName);
                  DebugPrintf("New List: %04X (%s)\n", newList, cptName);
            } else {
                  _skyCompact->fetchCptInfo(*logicList, &numElems, &type, cptName);
                  DebugPrintf(" Cpt %04X (%s) (%s)\n", *logicList, cptName, _skyCompact->nameForType(type));
      return true;

} // End of namespace Sky

Generated by  Doxygen 1.6.0   Back to index