home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / chip_20022115.iso / amiga / chipgame / scummvm_aga.lha / ScummVM_AGA / src / debug.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-01-05  |  4.6 KB  |  194 lines

  1. /* ScummVM - Scumm Interpreter
  2.  * Copyright (C) 2001  Ludvig Strigeus
  3.  *
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License
  6.  * as published by the Free Software Foundation; either version 2
  7.  * of the License, or (at your option) any later version.
  8.  
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17.  *
  18.  * $Header: /cvsroot/scummvm/scummvm/debug.cpp,v 1.6 2001/11/07 18:10:52 strigeus Exp $
  19.  *
  20.  */
  21.  
  22. #include "stdafx.h"
  23. #include "scumm.h"
  24.  
  25.  
  26. enum {
  27.     CMD_INVALID,
  28.     CMD_HELP,
  29.     CMD_QUIT,
  30.     CMD_GO,
  31.     CMD_ACTOR,
  32.     CMD_SCRIPTS,
  33.     CMD_EXIT
  34. };
  35.  
  36. void ScummDebugger::attach(Scumm *s) {
  37.     if (_s)
  38.         detach();
  39.  
  40.     _welcome = true;
  41.     _s = s;
  42.     s->_debugger = this;
  43.  
  44.     _go_amount = 1;
  45. }
  46.  
  47. bool ScummDebugger::do_command() {
  48.     int cmd;
  49.  
  50.     switch(get_command()) {
  51.     case CMD_HELP:
  52.         printf(
  53.                 "Debugger commands:\n"
  54.                 "(h)elp -> display this help text\n"
  55.                 "(q)uit -> quit the debugger\n"
  56.                 "(g)o [numframes] -> increase frame\n"
  57.                 "(a)ctor [actornum] -> show actor information\n"
  58.                 "(s)cripts -> show running scripts\n"
  59.                 "(e)xit -> exit game\n"
  60.                );
  61.         return true;
  62.  
  63.     case CMD_QUIT:
  64.         detach();
  65.         return false;
  66.  
  67.     case CMD_GO:
  68.         if (!_parameters[0])
  69.             _go_amount = 1;
  70.         else
  71.             _go_amount = atoi(_parameters);
  72.         return false;
  73.     case CMD_ACTOR:
  74.         if (!_parameters[0])
  75.             printActors(-1);
  76.         else
  77.             printActors(atoi(_parameters));
  78.         return true;
  79.     case CMD_SCRIPTS:
  80.         printScripts();
  81.         return true;
  82.     case CMD_EXIT:
  83.         exit(1);
  84.     }
  85.     /* this line is never reached */
  86. }
  87.  
  88. void ScummDebugger::enter() {
  89.     if (_welcome) {
  90.         _welcome = false;
  91.         printf("Debugging Mode entered!, please switch to this console for input.\n"
  92.                "Enter h to list all the debug commands\n");
  93.     }
  94.     while(do_command()) {}
  95. }
  96.  
  97.  
  98. void ScummDebugger::on_frame() {
  99.     if (_go_amount==0)
  100.         return;
  101.     if (!--_go_amount)
  102.         enter();
  103. }
  104.  
  105.  
  106. void ScummDebugger::detach() {
  107.     _s->_debugger = NULL;
  108.     _s = NULL;
  109. }
  110.  
  111. struct DebuggerCommands {
  112.     char text[8];
  113.     byte len;
  114.     byte id;
  115. };
  116.  
  117. static const DebuggerCommands debugger_commands[] = {
  118.     { "h", 1, CMD_HELP },
  119.     { "q", 1, CMD_QUIT },
  120.     { "g", 1, CMD_GO },
  121.     { "a", 1, CMD_ACTOR },
  122.     { "s", 1, CMD_SCRIPTS },
  123.     { "e", 1, CMD_EXIT },
  124.     { 0, 0, 0 },
  125. };
  126.  
  127. int ScummDebugger::get_command() {
  128.     const DebuggerCommands *dc;
  129.     char *s;
  130.     int i;
  131.  
  132.     do {
  133.         printf("debug> ");
  134.         if (!fgets(_cmd_buffer, sizeof(_cmd_buffer), stdin))
  135.             return CMD_QUIT;
  136.  
  137.         i = strlen(_cmd_buffer);
  138.         while (i>0 && _cmd_buffer[i-1]==10)
  139.             _cmd_buffer[--i] = 0;
  140.  
  141.         if (i==0)
  142.             continue;
  143.                         
  144.         dc = debugger_commands;
  145.         do {
  146.             if (!strncmp(_cmd_buffer, dc->text, dc->len)) {
  147.                 for(s=_cmd_buffer;*s;s++) {
  148.                     if (*s==32) { s++; break; }
  149.                 }
  150.                 _parameters = s;
  151.                 return _command = dc->id;
  152.             }
  153.         } while ((++dc)->text[0]);
  154.         
  155.         for(s=_cmd_buffer;*s;s++)
  156.             if (*s==32) { *s=0; break; }
  157.         printf("Invalid command '%s'. Type 'help' for a list of available commands.\n", _cmd_buffer);
  158.     } while (1);
  159. }
  160.  
  161. void ScummDebugger::printActors(int act) {
  162.     int i;
  163.     Actor *a;
  164.  
  165.     printf("+--------------------------------------------------------------+\n");
  166.     printf("|# |room|  x y   |elev|cos|width|box|mov|zp|frame|scale|spd|dir|\n");
  167.     printf("+--+----+--------+----+---+-----+---+---+--+-----+-----+---+---+\n");
  168.     for(i=1; i<13; i++) {
  169.         if (act==-1 || act==i) {
  170.             a = &_s->actor[i];
  171.             if (a->visible)
  172.                 printf("|%2d|%4d|%3d  %3d|%4d|%3d|%5d|%3d|%3d|%2d|%5d|%5d|%3d|%3d|\n",
  173.                     i,a->room,a->x,a->y,a->elevation,a->costume,a->width,a->walkbox,a->moving,a->neverZClip,a->animIndex,a->scalex,a->speedx,a->facing);
  174.         }
  175.     }
  176.     printf("+--------------------------------------------------------------+\n");
  177. }
  178.  
  179. void ScummDebugger::printScripts() {
  180.     int i;
  181.     ScriptSlot *ss;
  182.  
  183.     printf("+---------------------------------+\n");
  184.     printf("|# |num|sta|typ|un1|un2|fc|cut|un5|\n");
  185.     printf("+--+---+---+---+---+---+--+---+---+\n");
  186.     for(i=0; i<25; i++) {
  187.         ss = &_s->vm.slot[i];
  188.         if (ss->number) {
  189.             printf("|%2d|%3d|%3d|%3d|%3d|%3d|%2d|%3d|%3d|\n",
  190.                 i, ss->number, ss->status, ss->type, ss->unk1, ss->unk2, ss->freezeCount, ss->cutsceneOverride, ss->unk5);
  191.         }
  192.     }
  193.     printf("+---------------------------------+\n");
  194. }