[Scummvm-cvs-logs] CVS: tools descumm-tool.cpp,NONE,1.1 Makefile,1.18,1.19 Makefile.mingw,1.9,1.10 descumm.cpp,1.78,1.79 descumm.h,1.5,1.6 descumm6.cpp,1.117,1.118
Max Horn
fingolfin at users.sourceforge.net
Sat Sep 27 17:50:17 CEST 2003
Update of /cvsroot/scummvm/tools
In directory sc8-pr-cvs1:/tmp/cvs-serv28644
Modified Files:
Makefile Makefile.mingw descumm.cpp descumm.h descumm6.cpp
Added Files:
descumm-tool.cpp
Log Message:
enable some more warnings; merged descumm & descumm6; some cleanup
--- NEW FILE: descumm-tool.cpp ---
/* DeScumm - Scumm Script Disassembler
* Copyright (C) 2001 Ludvig Strigeus
* Copyright (C) 2002-2003 The ScummVM Team
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header: /cvsroot/scummvm/tools/descumm-tool.cpp,v 1.1 2003/09/28 00:49:33 fingolfin Exp $
*
*/
#include "descumm.h"
void ShowHelpAndExit()
{
printf("SCUMM Script decompiler\n"
"Syntax:\n"
"\tdescumm [-o] filename\n"
"Flags:\n"
"\t-1\tInput Script is v1\n"
"\t-2\tInput Script is v2\n"
"\t-3\tInput Script is v3\n"
"\t-4\tInput Script is v4\n"
"\t-5\tInput Script is v5\n"
"\t-6\tInput Script is v6\n"
"\t-7\tInput Script is v7\n"
"\t-8\tInput Script is v8\n"
"\t-p\tInput Script is from Humongous Entertainment game\n"
"\t-n\tUse Indy3-256 specific hacks\n"
"\t-z\tUse Zak256 specific hacks\n"
"\t-u\tScript is Unblocked/has no header\n"
"\t-o\tAlways Show offsets\n"
"\t-i\tDon't output ifs\n"
"\t-e\tDon't output else\n"
"\t-f\tDon't output else-if\n"
"\t-w\tDon't output while\n"
"\t-c\tDon't show opcode\n"
"\t-x\tDon't show offsets\n"
"\t-h\tHalt on error\n");
exit(0);
}
int skipVerbHeader_V12(byte *p)
{
byte code;
int offset = 15;
int minOffset = 255;
p += offset;
printf("Events:\n");
while ((code = *p++) != 0) {
offset = *p++;
printf(" %2X - %.4X\n", code, offset);
if (minOffset > offset)
minOffset = offset;
}
return minOffset;
}
int skipVerbHeader_V34(byte *p)
{
byte code;
int offset = GF_UNBLOCKED ? 17 : 19;
int minOffset = 255;
p += offset;
printf("Events:\n");
while ((code = *p++) != 0) {
offset = TO_LE_16(*(uint16 *)p);
p += 2;
printf(" %2X - %.4X\n", code, offset);
if (minOffset > offset)
minOffset = offset;
}
return minOffset;
}
byte *skipVerbHeader_V5(byte *p)
{
byte code;
printf("Events:\n");
while ((code = *p++) != 0) {
printf(" %2X - %.4X\n", code, TO_LE_16(*(uint16 *)p));
p += 2;
}
return p;
}
int skipVerbHeader_V67(byte *p)
{
byte code;
int offset = 8;
int minOffset = 255;
p += offset;
printf("Events:\n");
while ((code = *p++) != 0) {
offset = TO_LE_16(*(uint16 *)p);
p += 2;
printf(" %2X - %.4X\n", code, offset);
if (minOffset > offset)
minOffset = offset;
}
return minOffset;
}
byte *skipVerbHeader_V8(byte *p)
{
uint32 *ptr;
uint32 code;
int hdrlen;
ptr = (uint32 *)p;
while (TO_LE_32(*ptr++) != 0) {
ptr++;
}
hdrlen = (byte *)ptr - p;
ptr = (uint32 *)p;
while ((code = TO_LE_32(*ptr++)) != 0) {
printf(" %2d - %.4X\n", code, TO_LE_32(*ptr++) - hdrlen);
}
return (byte *)ptr;
}
int main(int argc, char *argv[])
{
FILE *in;
byte *mem, *memorg;
int len;
char *filename, *buf;
int i;
char *s;
scriptVersion = 0;
// Parse the arguments
filename = NULL;
for (i = 1; i < argc; i++) {
s = argv[i];
if (s && s[0] == '-') {
s++;
while (*s) {
switch (tolower(*s)) {
case '1':
scriptVersion = 1;
g_jump_opcode = 0x18;
GF_UNBLOCKED = true;
break;
case '2':
scriptVersion = 2;
g_jump_opcode = 0x18;
GF_UNBLOCKED = true;
break;
case '3':
scriptVersion = 3;
g_jump_opcode = 0x18;
break;
case '4':
scriptVersion = 4;
g_jump_opcode = 0x18;
break;
case '5':
scriptVersion = 5;
g_jump_opcode = 0x18;
break;
case 'n':
IndyFlag = 1; // Indy3
break;
case 'z':
ZakFlag = 1; // Zak
break;
case 'u':
GF_UNBLOCKED = true;
break;
case 'p':
HumongousFlag = true;
// Fall through
case '6':
scriptVersion = 6;
g_jump_opcode = 0x73;
break;
case '7':
scriptVersion = 7;
g_jump_opcode = 0x73;
break;
case '8':
scriptVersion = 8;
g_jump_opcode = 0x66;
break;
case 'o':
alwaysShowOffs = true;
break;
case 'i':
dontOutputIfs = true;
break;
case 'e':
dontOutputElse = true;
break;
case 'f':
dontOutputElseif = true;
break;
case 'w':
dontOutputWhile = true;
break;
case 'c':
dontShowOpcode = true;
break;
case 'x':
dontShowOffsets = true;
break;
case 'h':
haltOnError = true;
break;
default:
ShowHelpAndExit();
}
s++;
}
} else {
if (filename)
ShowHelpAndExit();
filename = s;
}
}
if (!filename || scriptVersion == 0)
ShowHelpAndExit();
in = fopen(filename, "rb");
if (!in) {
printf("Unable to open %s\n", filename);
return 1;
}
memorg = mem = (byte *)malloc(65536);
len = fread(mem, 1, 65536, in);
fclose(in);
size_of_code = len;
output = buf = (char *)malloc(8192);
offs_of_line = 0;
if (scriptVersion >= 6) {
if (size_of_code < 10) {
printf("File too small to be a script\n");
exit(0);
}
switch (TO_BE_32(*((uint32 *)mem))) {
case 'LSCR':
if (scriptVersion == 8) {
printf("Script# %d\n", TO_LE_32(*((int32 *)(mem+8))));
mem += 12;
} else if (scriptVersion == 7) {
printf("Script# %d\n", TO_LE_16(*((int16 *)(mem+8))));
mem += 10;
} else {
printf("Script# %d\n", (byte)mem[8]);
mem += 9;
}
break; /* Local script */
case 'SCRP':
mem += 8;
break; /* Script */
case 'ENCD':
mem += 8;
break; /* Entry code */
case 'EXCD':
mem += 8;
break; /* Exit code */
case 'VERB':
if (scriptVersion == 8)
mem = skipVerbHeader_V8(mem + 8);
else
offs_of_line = skipVerbHeader_V67(mem);
break; /* Verb */
default:
printf("Unknown script type!\n");
exit(0);
}
} else if (GF_UNBLOCKED) {
if (size_of_code < 4) {
printf("File too small to be a script\n");
exit(0);
}
// Hack to detect verb script: first 4 bytes should be file length
if (TO_LE_32(*((uint32 *)mem)) == size_of_code) {
if (scriptVersion <= 2)
offs_of_line = skipVerbHeader_V12(mem);
else
offs_of_line = skipVerbHeader_V34(mem );
} else {
mem += 4;
}
} else if (scriptVersion == 5) {
if (size_of_code < 8) {
printf("File too small to be a script\n");
exit(0);
}
switch (TO_BE_32(*((uint32 *)mem))) {
case 'LSCR':
printf("Script# %d\n", (byte)mem[8]);
mem += 9;
break; /* Local script */
case 'SCRP':
mem += 8;
break; /* Script */
case 'ENCD':
mem += 8;
break; /* Entry code */
case 'EXCD':
mem += 8;
break; /* Exit code */
case 'VERB':
offs_of_line = skipVerbHeader_V5(mem + 8) - mem;
break; /* Verb */
default:
printf("Unknown script type!\n");
exit(0);
}
} else {
if (size_of_code < 6) {
printf("File too small to be a script\n");
exit(0);
}
switch (TO_LE_16(*((uint16 *)mem + 2))) {
case MKID('LS'):
printf("Script# %d\n", (byte)mem[6]);
mem += 7;
break; /* Local script */
case MKID('SC'):
mem += 6;
break; /* Script */
case MKID('EN'):
mem += 6;
break; /* Entry code */
case MKID('EX'):
mem += 6;
break; /* Exit code */
case MKID('OC'):
offs_of_line = skipVerbHeader_V34(mem);
break; /* Verb */
default:
printf("Unknown script type!\n");
exit(0);
}
}
org_pos = mem;
cur_pos = org_pos + offs_of_line;
len -= mem - memorg;
while (cur_pos < mem + len) {
byte opcode = *cur_pos;
int j = num_block_stack;
buf[0] = 0;
switch (scriptVersion) {
case 1:
case 2:
next_line_V12(buf);
break;
case 3:
case 4:
case 5:
next_line_V345(buf);
break;
case 6:
case 7:
next_line_V67();
break;
case 8:
next_line_V8();
break;
}
if (buf[0]) {
writePendingElse();
if (haveElse) {
haveElse = false;
j--;
}
outputLine(buf, offs_of_line, opcode, j);
offs_of_line = get_curoffs();
}
while (indentBlock(get_curoffs())) {
outputLine("}", -1, -1, -1);
}
fflush(stdout);
}
printf("END\n");
/*
if (scriptVersion >= 6 && num_stack != 0) {
printf("Stack count: %d\n", num_stack);
if (num_stack > 0) {
printf("Stack contents:\n");
while (num_stack) {
buf[0] = 0;
se_astext(pop(), buf);
printf("%s\n", buf);
}
}
}
*/
free(memorg);
return 0;
}
Index: Makefile
===================================================================
RCS file: /cvsroot/scummvm/tools/Makefile,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- Makefile 10 Sep 2003 21:53:34 -0000 1.18
+++ Makefile 28 Sep 2003 00:49:33 -0000 1.19
@@ -5,12 +5,18 @@
CFLAGS := -g -O -Wall -Wstrict-prototypes -Wuninitialized -Wno-long-long -Wno-multichar
LDFLAGS :=
+# Additional warnings
+CFLAGS+= -Wshadow
+CFLAGS+= -pedantic
+CFLAGS+= -Wpointer-arith -Wcast-qual -Wcast-align
+# -Wconversion
+CFLAGS+= -Wshadow -Wimplicit -Wundef -Wwrite-strings
+
# Uncomment this if you are on a big endian system
# CFLAGS += -DSCUMM_BIG_ENDIAN
TARGETS := \
descumm$(EXEEXT) \
- descumm6$(EXEEXT) \
extract$(EXEEXT) \
mm_nes_extract$(EXEEXT) \
rescumm$(EXEEXT) \
@@ -19,10 +25,7 @@
all: $(TARGETS)
-descumm$(EXEEXT): descumm.o descumm-common.o
- $(CXX) $(LFLAGS) -o $@ $+
-
-descumm6$(EXEEXT): descumm6.o descumm-common.o
+descumm$(EXEEXT): descumm-tool.o descumm.o descumm6.o descumm-common.o
$(CXX) $(LFLAGS) -o $@ $+
extract$(EXEEXT): extract.o
@@ -41,7 +44,7 @@
$(CC) $(LFLAGS) -o $@ $+
-descumm.o descumm6.o descumm-common.o: descumm.h
+descumm.o descumm6.o descumm-common.o descumm-tool.o: descumm.h
clean:
rm -f *.o $(TARGETS)
Index: Makefile.mingw
===================================================================
RCS file: /cvsroot/scummvm/tools/Makefile.mingw,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- Makefile.mingw 11 Sep 2003 00:53:45 -0000 1.9
+++ Makefile.mingw 28 Sep 2003 00:49:33 -0000 1.10
@@ -9,7 +9,6 @@
mkdir -p $(SCUMMVMPATH)
mkdir -p $(SCUMMVMPATH)/tools
strip descumm.exe -o $(SCUMMVMPATH)/tools/descumm.exe
- strip descumm6.exe -o $(SCUMMVMPATH)/tools/descumm6.exe
strip extract.exe -o $(SCUMMVMPATH)/tools/extract.exe
strip mm_nes_extract.exe -o $(SCUMMVMPATH)/tools/mm_nes_extract.exe
strip rescumm.exe -o $(SCUMMVMPATH)/tools/rescumm.exe
Index: descumm.cpp
===================================================================
RCS file: /cvsroot/scummvm/tools/descumm.cpp,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -d -r1.78 -r1.79
--- descumm.cpp 15 Sep 2003 16:21:48 -0000 1.78
+++ descumm.cpp 28 Sep 2003 00:49:33 -0000 1.79
@@ -91,9 +91,6 @@
-void get_tok_V12(char *buf); // For V1 and V2
-void get_tok_V345(char *buf); // For V3, V4, V5
-
bool ZakFlag = false;
bool IndyFlag = false;
bool GF_UNBLOCKED = false;
@@ -707,9 +704,9 @@
case 0x6:
buf2 = strecpy(buf, "<");
if (scriptVersion <= 2)
- get_tok_V12(buf2);
+ next_line_V12(buf2);
else
- get_tok_V345(buf2);
+ next_line_V345(buf2);
strecpy(strchr(buf2, 0), ">");
AddToExprStack(buf);
break;
@@ -755,9 +752,9 @@
case 0x6:
sprintf(buf, "CALL (%.2X) ", *cur_pos);
if (scriptVersion <= 2)
- get_tok_V12(strchr(buf, 0));
+ next_line_V12(strchr(buf, 0));
else
- get_tok_V345(strchr(buf, 0));
+ next_line_V345(strchr(buf, 0));
break;
default:
sprintf(buf, "UNKNOWN %d", i);
@@ -1679,7 +1676,7 @@
}
}
-void get_tok_V12(char *buf)
+void next_line_V12(char *buf)
{
byte opcode = get_byte();
@@ -2268,7 +2265,7 @@
}
}
-void get_tok_V345(char *buf)
+void next_line_V345(char *buf)
{
byte opcode = get_byte();
@@ -2987,284 +2984,4 @@
}
sprintf(buf, "ERROR: Unknown opcode %.2X!", opcode);
}
-}
-
-void ShowHelpAndExit()
-{
- printf("SCUMM Script decompiler\n"
- "Syntax:\n"
- "\tdescumm [-o] filename\n"
- "Flags:\n"
- "\t-1\tInput Script is v1\n"
- "\t-2\tInput Script is v2\n"
- "\t-3\tInput Script is v3\n"
- "\t-4\tInput Script is v4\n"
- "\t-5\tInput Script is v5\n"
- "\t-n\tUse Indy3-256 specific hacks\n"
- "\t-z\tUse Zak256 specific hacks\n"
- "\t-u\tScript is Unblocked/has no header\n"
- "\t-o\tAlways Show offsets\n"
- "\t-i\tDon't output ifs\n"
- "\t-e\tDon't output else\n"
- "\t-f\tDon't output else-if\n"
- "\t-w\tDon't output while\n"
- "\t-c\tDon't show opcode\n"
- "\t-x\tDon't show offsets\n"
- "\t-h\tHalt on error\n");
- exit(0);
-}
-
-int skipVerbHeader_V12(byte *p)
-{
- byte code;
- int offset = 15;
- int minOffset = 255;
- p += offset;
-
- printf("Events:\n");
-
- while ((code = *p++) != 0) {
- offset = *p++;
- printf(" %2X - %.4X\n", code, offset);
- if (minOffset > offset)
- minOffset = offset;
- }
- return minOffset;
-}
-
-int skipVerbHeader_V34(byte *p)
-{
- byte code;
- int offset = GF_UNBLOCKED ? 17 : 19;
- int minOffset = 255;
- p += offset;
-
- printf("Events:\n");
-
- while ((code = *p++) != 0) {
- offset = TO_LE_16(*(uint16 *)p);
- p += 2;
- printf(" %2X - %.4X\n", code, offset);
- if (minOffset > offset)
- minOffset = offset;
- }
- return minOffset;
-}
-
-byte *skipVerbHeader_V5(byte *p)
-{
- byte code;
-
- printf("Events:\n");
-
- while ((code = *p++) != 0) {
- printf(" %2X - %.4X\n", code, TO_LE_16(*(uint16 *)p));
- p += 2;
- }
- return p;
-}
-
-
-int main(int argc, char *argv[])
-{
- FILE *in;
- byte *mem, *memorg;
- int len;
- char *filename, *buf;
- int i;
- char *s;
-
- scriptVersion = 3;
- g_jump_opcode = 0x18;
-
- // Parse the arguments
- filename = NULL;
- for (i = 1; i < argc; i++) {
- s = argv[i];
-
- if (s && s[0] == '-') {
- s++;
- while (*s) {
- switch (tolower(*s)) {
- case '1':
- scriptVersion = 1;
- GF_UNBLOCKED = true;
- break;
- case '2':
- scriptVersion = 2;
- GF_UNBLOCKED = true;
- break;
- case '3':
- scriptVersion = 3;
- break;
- case '4':
- scriptVersion = 4;
- break;
- case '5':
- scriptVersion = 5;
- break;
- case 'n':
- IndyFlag = 1; // Indy3
- break;
- case 'z':
- ZakFlag = 1; // Zak
- break;
- case 'u':
- GF_UNBLOCKED = true;
- break;
-
- case 'o':
- alwaysShowOffs = true;
- break;
- case 'i':
- dontOutputIfs = true;
- break;
- case 'e':
- dontOutputElse = true;
- break;
- case 'f':
- dontOutputElseif = true;
- break;
- case 'w':
- dontOutputWhile = true;
- break;
- case 'c':
- dontShowOpcode = true;
- break;
- case 'x':
- dontShowOffsets = true;
- break;
- case 'h':
- haltOnError = true;
- break;
- default:
- ShowHelpAndExit();
- }
- s++;
- }
- } else {
- if (filename)
- ShowHelpAndExit();
- filename = s;
- }
- }
-
- if (!filename)
- ShowHelpAndExit();
-
- in = fopen(filename, "rb");
- if (!in) {
- printf("Unable to open %s\n", filename);
- return 1;
- }
-
- memorg = mem = (byte *)malloc(65536);
- len = fread(mem, 1, 65536, in);
- fclose(in);
- size_of_code = len;
-
- buf = (char *)malloc(4096);
-
- offs_of_line = 0;
-
- if (GF_UNBLOCKED) {
- if (size_of_code < 4) {
- printf("File too small to be a script\n");
- exit(0);
- }
- // Hack to detect verb script: first 4 bytes should be file length
- if (TO_LE_32(*((uint32 *)mem)) == size_of_code) {
- if (scriptVersion <= 2)
- offs_of_line = skipVerbHeader_V12(mem);
- else
- offs_of_line = skipVerbHeader_V34(mem );
- } else {
- mem += 4;
- }
- } else if (scriptVersion == 5) {
- if (size_of_code < 8) {
- printf("File too small to be a script\n");
- exit(0);
- }
- switch (TO_BE_32(*((uint32 *)mem))) {
- case 'LSCR':
- printf("Script# %d\n", (byte)mem[8]);
- mem += 9;
- break; /* Local script */
- case 'SCRP':
- mem += 8;
- break; /* Script */
- case 'ENCD':
- mem += 8;
- break; /* Entry code */
- case 'EXCD':
- mem += 8;
- break; /* Exit code */
- case 'VERB':
- offs_of_line = skipVerbHeader_V5(mem + 8) - mem;
- break; /* Verb */
- default:
- printf("Unknown script type!\n");
- exit(0);
- }
- } else {
- if (size_of_code < 6) {
- printf("File too small to be a script\n");
- exit(0);
- }
- switch (TO_LE_16(*((uint16 *)mem + 2))) {
- case MKID('LS'):
- printf("Script# %d\n", (byte)mem[6]);
- mem += 7;
- break; /* Local script */
- case MKID('SC'):
- mem += 6;
- break; /* Script */
- case MKID('EN'):
- mem += 6;
- break; /* Entry code */
- case MKID('EX'):
- mem += 6;
- break; /* Exit code */
- case MKID('OC'):
- offs_of_line = skipVerbHeader_V34(mem);
- break; /* Verb */
- default:
- printf("Unknown script type!\n");
- exit(0);
- }
- }
-
- org_pos = mem;
- cur_pos = org_pos + offs_of_line;
- len -= mem - memorg;
-
- while (cur_pos < mem + len) {
- byte opcode = *cur_pos;
- int j = num_block_stack;
- buf[0] = 0;
- if (scriptVersion <= 2)
- get_tok_V12(buf);
- else
- get_tok_V345(buf);
- if (buf[0]) {
- writePendingElse();
- if (haveElse) {
- haveElse = false;
- j--;
- }
- outputLine(buf, offs_of_line, opcode, j);
- offs_of_line = get_curoffs();
- }
- while (indentBlock(get_curoffs())) {
- outputLine("}", -1, -1, -1);
- }
- fflush(stdout);
- }
-
- printf("END\n");
-
- free(memorg);
-
- return 0;
}
Index: descumm.h
===================================================================
RCS file: /cvsroot/scummvm/tools/descumm.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- descumm.h 15 Sep 2003 16:21:48 -0000 1.5
+++ descumm.h 28 Sep 2003 00:49:33 -0000 1.6
@@ -34,6 +34,9 @@
#include <process.h>
#endif
+//
+// Various utility macros
+//
#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
@@ -144,5 +147,20 @@
extern bool maybeAddElse(uint cur, uint to);
extern bool maybeAddElseIf(uint cur, uint elseto, uint to);
extern void writePendingElse();
+
+//
+// Entry points for the descumming
+//
+extern void next_line_V12(char *buf); // For V1 and V2
+extern void next_line_V345(char *buf); // For V3, V4, V5
+extern void next_line_V67();
+extern void next_line_V8();
+extern char *output;
+extern bool HumongousFlag;
+extern bool ZakFlag;
+extern bool IndyFlag;
+extern bool GF_UNBLOCKED;
+
+
#endif
Index: descumm6.cpp
===================================================================
RCS file: /cvsroot/scummvm/tools/descumm6.cpp,v
retrieving revision 1.117
retrieving revision 1.118
diff -u -d -r1.117 -r1.118
--- descumm6.cpp 15 Sep 2003 16:21:48 -0000 1.117
+++ descumm6.cpp 28 Sep 2003 00:49:33 -0000 1.118
@@ -116,11 +116,11 @@
"%"
};
-StackEnt *stack[128];
-int num_stack;
+static StackEnt *stack[128];
+static int num_stack = -1;
bool HumongousFlag = false;
-char *output;
+char *output = 0; // FIXME: it is evil to have a global output buffer like this
const char *var_names6[] = {
/* 0 */
@@ -595,45 +595,6 @@
exit(1);
}
-byte *skipVerbHeader_V8(byte *p)
-{
- uint32 *ptr;
- uint32 code;
- int hdrlen;
-
- ptr = (uint32 *)p;
- while (TO_LE_32(*ptr++) != 0) {
- ptr++;
- }
- hdrlen = (byte *)ptr - p;
-
- ptr = (uint32 *)p;
- while ((code = TO_LE_32(*ptr++)) != 0) {
- printf(" %2d - %.4X\n", code, TO_LE_32(*ptr++) - hdrlen);
- }
-
- return (byte *)ptr;
-}
-
-int skipVerbHeader_V67(byte *p)
-{
- byte code;
- int offset = 8;
- int minOffset = 255;
- p += offset;
-
- printf("Events:\n");
-
- while ((code = *p++) != 0) {
- offset = TO_LE_16(*(uint16 *)p);
- p += 2;
- printf(" %2X - %.4X\n", code, offset);
- if (minOffset > offset)
- minOffset = offset;
- }
- return minOffset;
-}
-
StackEnt *se_new(int type)
{
StackEnt *se = (StackEnt *) malloc(sizeof(StackEnt));
@@ -2097,7 +2058,7 @@
ext("|createBoxMatrix");
break;
case 0x9B:
- ext("x" "resourceRoutines\0"
+ ext("x" "resourceOps\0"
"\x64p|loadScript,"
"\x65p|loadSound,"
"\x66p|loadCostume,"
@@ -2135,65 +2096,65 @@
"\xD5p|setPalette");
break;
case 0x9D:
- ext("x" "actorSet\0"
+ ext("x" "actorOps\0"
"\xC5p|setCurActor,"
- "\x4Cp|setActorCostume,"
- "\x4Dpp|setActorWalkSpeed,"
- "\x4El|setActorSound,"
- "\x4Fp|setActorWalkFrame,"
- "\x50pp|setActorTalkFrame,"
- "\x51p|setActorStandFrame,"
+ "\x4Cp|setCostume,"
+ "\x4Dpp|setWalkSpeed,"
+ "\x4El|setSound,"
+ "\x4Fp|setWalkFrame,"
+ "\x50pp|setTalkFrame,"
+ "\x51p|setStandFrame,"
"\x52ppp|actorSet:82:??,"
- "\x53|initActor,"
- "\x54p|setActorElevation,"
- "\x55|setActorDefAnim,"
- "\x56pp|setActorPalette,"
- "\x57p|setActorTalkColor,"
- "\x58s|setActorName,"
- "\x59p|setActorInitFrame,"
- "\x5Bp|setActorWidth,"
- "\x5Cp|setActorScale,"
- "\x5D|setActorNeverZClip,"
- "\x5Ep|setActorAlwayZClip?,"
- "\xE1p|setActorAlwayZClip?,"
- "\x5F|setActorIgnoreBoxes,"
- "\x60|setActorFollowBoxes,"
- "\x61|setActorAnimSpeed,"
- "\x62|setActorShadowMode,"
- "\x63pp|setActorTalkPos,"
- "\xC6p|setActorAnimVar,"
- "\xD7|setActorIgnoreTurnsOn,"
- "\xD8|setActorIgnoreTurnsOff,"
- "\xD9|initActorLittle,"
- "\xE3p|setActorLayer,"
- "\xE4p|setActorWalkScript,"
- "\xE5|setActorStanding,"
- "\xE6p|setActorDirection,"
- "\xE7p|actorTurnToDirection,"
- "\xE9|freezeActor,"
- "\xEA|unfreezeActor,"
+ "\x53|init,"
+ "\x54p|setElevation,"
+ "\x55|setDefAnim,"
+ "\x56pp|setPalette,"
+ "\x57p|setTalkColor,"
+ "\x58s|setName,"
+ "\x59p|setInitFrame,"
+ "\x5Bp|setWidth,"
+ "\x5Cp|setScale,"
+ "\x5D|setNeverZClip,"
+ "\x5Ep|setAlwayZClip?,"
+ "\xE1p|setAlwayZClip?,"
+ "\x5F|setIgnoreBoxes,"
+ "\x60|setFollowBoxes,"
+ "\x61|setAnimSpeed,"
+ "\x62|setShadowMode,"
+ "\x63pp|setTalkPos,"
+ "\xC6p|setAnimVar,"
+ "\xD7|setIgnoreTurnsOn,"
+ "\xD8|setIgnoreTurnsOff,"
+ "\xD9|initLittle,"
+ "\xE3p|setLayer,"
+ "\xE4p|setWalkScript,"
+ "\xE5|setStanding,"
+ "\xE6p|setDirection,"
+ "\xE7p|turnToDirection,"
+ "\xE9|freeze,"
+ "\xEA|unfreeze,"
"\xEBp|setTalkScript");
break;
case 0x9E:
ext("x" "verbOps\0"
"\xC4p|setCurVerb,"
- "\x7Cp|verbLoadImg,"
- "\x7Ds|verbLoadString,"
- "\x7Ep|verbSetColor,"
- "\x7Fp|verbSetHiColor,"
- "\x80pp|verbSetXY,"
- "\x81|verbSetCurmode1," // = verbOn ?
- "\x82|verbSetCurmode0," // = verbOff ?
- "\x83|verbKill,"
- "\x84|verbInit,"
- "\x85p|verbSetDimColor,"
- "\x86|verbSetCurmode2," // = verbDim ?
- "\x87p|verbSetKey,"
- "\x88|verbSetCenter,"
- "\x89p|verbSetToString,"
- "\x8Bpp|verbSetToObject,"
- "\x8Cp|verbSetBkColor,"
- "\xFF|verbRedraw");
+ "\x7Cp|loadImg,"
+ "\x7Ds|loadString,"
+ "\x7Ep|setColor,"
+ "\x7Fp|setHiColor,"
+ "\x80pp|setXY,"
+ "\x81|setOn,"
+ "\x82|setOff,"
+ "\x83|kill,"
+ "\x84|init,"
+ "\x85p|setDimColor,"
+ "\x86|setDimmed,"
+ "\x87p|setKey,"
+ "\x88|setCenter,"
+ "\x89p|setToString,"
+ "\x8Bpp|setToObject,"
+ "\x8Cp|setBkColor,"
+ "\xFF|redraw");
break;
case 0x9F:
ext("rpp|getActorFromXY");
@@ -2439,203 +2400,4 @@
invalidop(NULL, code);
break;
}
-}
-
-
-void ShowHelpAndExit()
-{
- printf("SCUMM Script decompiler\n"
- "Syntax:\n"
- "\tdescumm6 [-o] filename\n"
- "Flags:\n"
- "\t-6\tInput Script is v6\n"
- "\t-7\tInput Script is v7\n"
- "\t-8\tInput Script is v8\n"
- "\t-o\tAlways Show offsets\n"
- "\t-p\tInput Script is from Humongous Entertainment game\n"
- "\t-i\tDon't output ifs\n"
- "\t-e\tDon't output else\n"
- "\t-f\tDon't output else-if\n"
- "\t-w\tDon't output while\n"
- "\t-c\tDon't show opcode\n"
- "\t-x\tDon't show offsets\n"
- "\t-h\tHalt on error\n");
- exit(0);
-}
-
-int main(int argc, char *argv[])
-{
- FILE *in;
- byte *mem, *memorg;
- int len;
- char *filename, *buf;
- int i;
- char *s;
-
- scriptVersion = 6;
- g_jump_opcode = 0x73;
-
- // Parse the arguments
- filename = NULL;
- for (i = 1; i < argc; i++) {
- s = argv[i];
-
- if (s && s[0] == '-') {
- s++;
- while (*s) {
- switch (tolower(*s)) {
- case '6':
- scriptVersion = 6;
- g_jump_opcode = 0x73;
- break;
- case '7':
- scriptVersion = 7;
- g_jump_opcode = 0x73;
- break;
- case '8':
- scriptVersion = 8;
- g_jump_opcode = 0x66;
- break;
-
- case 'o':
- alwaysShowOffs = true;
- break;
- case 'p':
- scriptVersion = 6;
- g_jump_opcode = 0x73;
- HumongousFlag = true;
- break;
- case 'i':
- dontOutputIfs = true;
- break;
- case 'e':
- dontOutputElse = true;
- break;
- case 'f':
- dontOutputElseif = true;
- break;
- case 'w':
- dontOutputWhile = true;
- break;
- case 'c':
- dontShowOpcode = true;
- break;
- case 'x':
- dontShowOffsets = true;
- break;
- case 'h':
- haltOnError = true;
- break;
- default:
- ShowHelpAndExit();
- }
- s++;
- }
- } else {
- if (filename)
- ShowHelpAndExit();
- filename = s;
- }
- }
-
- if (!filename)
- ShowHelpAndExit();
-
- in = fopen(filename, "rb");
- if (!in) {
- printf("Unable to open %s\n", filename);
- return 1;
- }
-
- memorg = mem = (byte *)malloc(65536);
- len = fread(mem, 1, 65536, in);
- fclose(in);
- size_of_code = len;
-
- if (size_of_code < 10) {
- printf("File too small to be a script\n");
- exit(0);
- }
-
- output = buf = (char *)malloc(8192);
-
- offs_of_line = 0;
-
- switch (TO_BE_32(*((uint32 *)mem))) {
- case 'LSCR':
- if (scriptVersion == 8) {
- printf("Script# %d\n", TO_LE_32(*((int32 *)(mem+8))));
- mem += 12;
- } else if (scriptVersion == 7) {
- printf("Script# %d\n", TO_LE_16(*((int16 *)(mem+8))));
- mem += 10;
- } else {
- printf("Script# %d\n", (byte)mem[8]);
- mem += 9;
- }
- break; /* Local script */
- case 'SCRP':
- mem += 8;
- break; /* Script */
- case 'ENCD':
- mem += 8;
- break; /* Entry code */
- case 'EXCD':
- mem += 8;
- break; /* Exit code */
- case 'VERB':
- if (scriptVersion == 8)
- mem = skipVerbHeader_V8(mem + 8);
- else
- offs_of_line = skipVerbHeader_V67(mem);
- break; /* Verb */
- default:
- printf("Unknown script type!\n");
- exit(0);
- }
-
- org_pos = mem;
- cur_pos = org_pos + offs_of_line;
- len -= mem - memorg;
-
- while (cur_pos < mem + len) {
- byte opcode = *cur_pos;
- int j = num_block_stack;
- buf[0] = 0;
- if (scriptVersion == 8)
- next_line_V8();
- else
- next_line_V67();
- if (buf[0]) {
- writePendingElse();
- if (haveElse) {
- haveElse = false;
- j--;
- }
- outputLine(buf, offs_of_line, opcode, j);
- offs_of_line = get_curoffs();
- }
- while (indentBlock(get_curoffs())) {
- outputLine("}", -1, -1, -1);
- }
- fflush(stdout);
- }
-
- printf("END\n");
-
- if (scriptVersion >= 6 && num_stack != 0) {
- printf("Stack count: %d\n", num_stack);
- if (num_stack > 0) {
- printf("Stack contents:\n");
- while (num_stack) {
- buf[0] = 0;
- se_astext(pop(), buf);
- printf("%s\n", buf);
- }
- }
- }
-
- free(memorg);
-
- return 0;
}
More information about the Scummvm-git-logs
mailing list