aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Brown2002-04-26 14:13:39 +0000
committerJames Brown2002-04-26 14:13:39 +0000
commit965b96b4895f0a5ad203abd0d9b48cc438447b31 (patch)
tree9a4b3281658244abf176718c991e1b66eadcf258
parentab2d1d03faa0e1d0f38a8972f85a778a2bbd9158 (diff)
downloadscummvm-rg350-965b96b4895f0a5ad203abd0d9b48cc438447b31.tar.gz
scummvm-rg350-965b96b4895f0a5ad203abd0d9b48cc438447b31.tar.bz2
scummvm-rg350-965b96b4895f0a5ad203abd0d9b48cc438447b31.zip
Add enhanced debugging patch.
svn-id: r4090
-rw-r--r--gameDetector.cpp9
-rw-r--r--readme.txt4
-rw-r--r--resource.cpp57
-rw-r--r--script.cpp11
-rw-r--r--scumm.h2
-rw-r--r--scummvm.cpp31
6 files changed, 92 insertions, 22 deletions
diff --git a/gameDetector.cpp b/gameDetector.cpp
index 81542ea043..03aba1b468 100644
--- a/gameDetector.cpp
+++ b/gameDetector.cpp
@@ -32,11 +32,11 @@
static const char USAGE_STRING[] =
"ScummVM - Scumm Interpreter\n"
"Syntax:\n"
- "\tscummvm [-v] [-d] [-n] [-b<num>] [-t<num>] [-s<num>] [-p<path>] [-m<num>] [-f] game\n"
+ "\tscummvm [-v] [-d[<num>]] [-n] [-b<num>] [-t<num>] [-s<num>] [-p<path>] [-m<num>] [-f] game\n"
"Flags:\n"
"\tv - show version info and exit\n"
"\tc<num> - use cdrom <num> for cd audio\n"
- "\td - enable debug output\n"
+ "\td[<num>]- enable debug output (level <num>)\n"
"\tn - no subtitles for speech\n"
"\tb<num> - start in room <num>\n"
"\tt<num> - set music tempo. Suggested: 1F0000\n"
@@ -83,7 +83,10 @@ void GameDetector::parseCommandLine(int argc, char **argv)
break;
case 'd':
_debugMode = true;
- break;
+ if (*(s+1) != '\0')
+ _debugLevel = atoi(s+1);
+ debug(1,"Debugmode (level %d) on", _debugLevel);
+ goto NextArg;
case 'n':
_noSubtitles = true;
break;
diff --git a/readme.txt b/readme.txt
index 6442af4c4d..595d2cbdd9 100644
--- a/readme.txt
+++ b/readme.txt
@@ -130,6 +130,9 @@ Visual C++ are supported. If you wish to use MP3-compressed CD tracks or
COMPRESSED_SOUND_FILE. Tools for compressing .SOU files to .SO3 files can be
found in the 'tools' CVS module, or in the 'scummvm-tools' package.
+On Win9x/NT/XP you can define WIN_DBG and attach WinDbg to browse the debug
+messages (see www.sysinternals.com/ntw2k/freeware/debugview.shtml).
+
GCC:
* Type make (or gmake if that's what GNU make is called on your
system) and hopefully ScummVM will compile for you.
@@ -199,6 +202,7 @@ Command Line Options:
-n - Disable subtitles. Use with games that have voice.
-r - Enable Roland conversion. Try if music sounds incorrect.
-a - Enable amiga pal conversion, for playing Amiga versions
+ -d[<num>] - Set debug verbosity to <num>
In game Hot Keys:
-----------------
diff --git a/resource.cpp b/resource.cpp
index 6cb4366eb4..2dba4ff9b8 100644
--- a/resource.cpp
+++ b/resource.cpp
@@ -357,7 +357,7 @@ void Scumm::readResTypeList(int id, uint32 tag, const char *name)
int num;
int i;
- debug(9, "readResTypeList(%d,%x,%s)", id, FROM_LE_32(tag), name);
+ debug(9, "readResTypeList(%s,%x,%s)", resTypeFromId(id), FROM_LE_32(tag), name);
num = fileReadWordLE();
@@ -392,8 +392,7 @@ void Scumm::readResTypeList(int id, uint32 tag, const char *name)
void Scumm::allocResTypeData(int id, uint32 tag, int num, const char *name,
int mode)
{
- debug(9, "allocResTypeData(%d,%x,%d,%s,%d)", id, FROM_LE_32(tag), num, name,
- mode);
+ debug(9, "allocResTypeData(%s/%s,%x,%d,%d)", resTypeFromId(id), name, FROM_LE_32(tag), num, mode);
assert(id >= 0 && id < (int)(sizeof(res.mode) / sizeof(res.mode[0])));
if (num >= 2000) {
@@ -444,7 +443,7 @@ void Scumm::ensureResourceLoaded(int type, int i)
{
void *addr;
- debug(9, "ensureResourceLoaded(%d,%d)", type, i);
+ debug(9, "ensureResourceLoaded(%s,%d)", resTypeFromId(type), i);
if (type == rtRoom && i > 127) {
i = _resourceMapper[i & 127];
@@ -470,7 +469,7 @@ int Scumm::loadResource(int type, int idx)
uint32 fileOffs;
uint32 size, tag;
-// debug(1, "loadResource(%d,%d)", type,idx);
+// debug(1, "loadResource(%s,%d)", resTypeFromId(type),idx);
if (type == rtCharset && (_features & GF_SMALL_HEADER)) {
loadCharset(idx);
@@ -545,7 +544,7 @@ int Scumm::readSoundResource(int type, int idx)
int pri, best_pri;
uint32 best_size = 0, best_offs = 0;
- debug(9, "readSoundResource(%d,%d)", type, idx);
+ debug(9, "readSoundResource(%s,%d)", resTypeFromId(type), idx);
pos = 0;
@@ -621,23 +620,27 @@ int Scumm::getResourceRoomNr(int type, int idx)
byte *Scumm::getResourceAddress(int type, int idx)
{
byte *ptr;
-
- debug(9, "getResourceAddress(%d,%d)", type, idx);
+
CHECK_HEAP validateResource("getResourceAddress", type, idx);
- if (!res.address[type])
+ if (!res.address[type]) {
+ debug(9, "getResourceAddress(%s,%d) == NULL", resTypeFromId(type), idx);
return NULL;
+ }
if (res.mode[type] && !res.address[type][idx]) {
ensureResourceLoaded(type, idx);
}
- if (!(ptr = (byte *)res.address[type][idx]))
+ if (!(ptr = (byte *)res.address[type][idx])) {
+ debug(9, "getResourceAddress(%s,%d) == NULL", resTypeFromId(type), idx);
return NULL;
+ }
setResourceCounter(type, idx, 1);
+ debug(9, "getResourceAddress(%s,%d) == %ld", resTypeFromId(type), idx, ptr + sizeof(MemBlkHeader));
return ptr + sizeof(MemBlkHeader);
}
@@ -680,7 +683,8 @@ byte *Scumm::createResource(int type, int idx, uint32 size)
{
byte *ptr;
- CHECK_HEAP debug(9, "createResource(%d,%d,%d)", type, idx, size);
+ CHECK_HEAP
+ debug(9, "createResource(%s,%d,%d)", resTypeFromId(type), idx, size);
validateResource("allocating", type, idx);
nukeResource(type, idx);
@@ -703,7 +707,7 @@ byte *Scumm::createResource(int type, int idx, uint32 size)
void Scumm::validateResource(const char *str, int type, int idx)
{
if (type < rtFirst || type > rtLast || (uint) idx >= (uint) res.num[type]) {
- warning("%s Illegal Glob type %d num %d", str, type, idx);
+ warning("%s Illegal Glob type %s (%d) num %d", str, resTypeFromId(type), type, idx);
}
}
@@ -711,7 +715,7 @@ void Scumm::nukeResource(int type, int idx)
{
byte *ptr;
- debug(9, "nukeResource(%d,%d)", type, idx);
+ debug(9, "nukeResource(%s,%d)", resTypeFromId(type), idx);
CHECK_HEAP if (!res.address[type])
return;
@@ -974,7 +978,7 @@ void Scumm::expireResources(uint32 size)
increaseResourceCounter();
- debug(1, "Expired resources, mem %d -> %d", oldAllocatedSize,
+ debug(5, "Expired resources, mem %d -> %d", oldAllocatedSize,
_allocatedSize);
}
@@ -1225,3 +1229,28 @@ uint16 newTag2Old(uint32 oldTag)
}
+char *Scumm::resTypeFromId(int id) {
+ static char buf[100];
+
+ switch(id) {
+ case rtRoom: sprintf(buf, "Room"); break;
+ case rtScript: sprintf(buf, "Script"); break;
+ case rtCostume: sprintf(buf, "Costume"); break;
+ case rtSound: sprintf(buf, "Sound"); break;
+ case rtInventory: sprintf(buf, "Inventory"); break;
+ case rtCharset: sprintf(buf, "Charset"); break;
+ case rtString: sprintf(buf, "String"); break;
+ case rtVerb: sprintf(buf, "Verb"); break;
+ case rtActorName: sprintf(buf, "ActorName"); break;
+ case rtBuffer: sprintf(buf, "Buffer"); break;
+ case rtScaleTable:sprintf(buf, "ScaleTable"); break;
+ case rtTemp: sprintf(buf, "Temp"); break;
+ case rtFlObject: sprintf(buf, "FlObject"); break;
+ case rtMatrix: sprintf(buf, "Matrix"); break;
+ case rtBox: sprintf(buf, "Box"); break;
+ case rtLast: sprintf(buf, "Last"); break;
+ case rtNumTypes: sprintf(buf, "NumTypes"); break;
+ default: sprintf(buf,"%d", id);
+ }
+ return buf;
+}
diff --git a/script.cpp b/script.cpp
index f9dcefce26..fffcd93081 100644
--- a/script.cpp
+++ b/script.cpp
@@ -274,7 +274,7 @@ void Scumm::executeScript()
_opcode = fetchScriptByte();
_scriptPointerStart = _scriptPointer;
vm.slot[_currentScript].didexec = 1;
- //debug(1, "Script %d: [%X] %s()", vm.slot[_currentScript].number, _opcode, _opcodes_lookup[_opcode]);
+ debug(9, "Script %d: [%X] %s()", vm.slot[_currentScript].number, _opcode, _opcodes_lookup[_opcode]);
op = getOpcode(_opcode);
(this->*op) ();
}
@@ -358,9 +358,12 @@ void Scumm::writeVar(uint var, int value)
checkRange(_numVariables - 1, 0, var, "Variable %d out of range(w)");
_vars[var] = value;
- if ((_varwatch == (int)var) || (_varwatch == 0))
- printf("vars[%d] = %d (via script %d)\n", var, value,
- vm.slot[_currentScript].number);
+ if ((_varwatch == (int)var) || (_varwatch == 0)) {
+ if (vm.slot[_currentScript].number < 100)
+ debug(0, "vars[%d] = %d (via script-%d)", var, value, vm.slot[_currentScript].number);
+ else
+ debug(0, "vars[%d] = %d (via room-%d-%d)", var, value, _currentRoom, vm.slot[_currentScript].number);
+ }
return;
}
diff --git a/scumm.h b/scumm.h
index d01d06335e..d384b6e84e 100644
--- a/scumm.h
+++ b/scumm.h
@@ -812,6 +812,7 @@ public:
bool openResourceFile(const char *filename);
void loadPtrToResource(int type, int i, byte *ptr);
void readResTypeList(int id, uint32 tag, const char *name);
+ char *resTypeFromId(int id);
void allocResTypeData(int id, uint32 tag, int num, const char *name, int mode);
byte *createResource(int type, int index, uint32 size);
void nukeResource(int type, int i);
@@ -1842,6 +1843,7 @@ struct Serializer {
extern const uint32 IMxx_tags[];
extern const byte default_scale_table[768];
+extern uint16 _debugLevel;
void outputdisplay2(Scumm *s, int disp);
extern const byte revBitMask[8];
diff --git a/scummvm.cpp b/scummvm.cpp
index e1ee02aba1..9201e8e041 100644
--- a/scummvm.cpp
+++ b/scummvm.cpp
@@ -1048,6 +1048,10 @@ int Scumm::normalizeAngle(int angle)
void NORETURN CDECL error(const char *s, ...)
{
char buf[1024];
+#if defined( USE_WINDBG )
+ char buf2[1024];
+#endif
+
va_list va;
va_start(va, s);
@@ -1060,8 +1064,21 @@ void NORETURN CDECL error(const char *s, ...)
g_scumm->_roomResource,
ss->number,
g_scumm->_scriptPointer - g_scumm->_scriptOrgPointer, buf);
+#if defined( USE_WINDBG )
+ sprintf(buf2, "Error(%d:%d:0x%X): %s!\n",
+ g_scumm->_roomResource,
+ ss->number,
+ g_scumm->_scriptPointer - g_scumm->_scriptOrgPointer,
+ buf);
+ OutputDebugString(buf2);
+#endif
+
} else {
fprintf(stderr, "Error: %s!\n", buf);
+#if defined( USE_WINDBG )
+ sprintf(&buf[strlen(buf)], "\n");
+ OutputDebugString(buf);
+#endif
}
// Doesn't wait for any keypress!! Is it intended to?
exit(1);
@@ -1077,20 +1094,32 @@ void CDECL warning(const char *s, ...)
va_end(va);
fprintf(stderr, "WARNING: %s!\n", buf);
+#if defined( USE_WINDBG )
+ sprintf(&buf[strlen(buf)], "\n");
+ OutputDebugString(buf);
+#endif
}
+uint16 _debugLevel = 1;
+
void CDECL debug(int level, const char *s, ...)
{
char buf[1024];
va_list va;
- if (level > 5)
+ if (level > _debugLevel)
return;
va_start(va, s);
vsprintf(buf, s, va);
va_end(va);
printf("%s\n", buf);
+
+#if defined( USE_WINDBG )
+ sprintf(&buf[strlen(buf)], "\n");
+ OutputDebugString(buf);
+#endif
+
fflush(stdout);
}