[Scummvm-cvs-logs] CVS: tools descumm.h,NONE,1.1 descumm.cpp,1.32,1.33 descumm6.cpp,1.94,1.95
Max Horn
fingolfin at users.sourceforge.net
Sat May 10 10:39:13 CEST 2003
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/scumm gfx.cpp,2.82,2.83 scumm.h,1.180,1.181 scummvm.cpp,2.133,2.134
- Next message: [Scummvm-cvs-logs] CVS: tools descumm-common.cpp,NONE,1.1 descumm.h,1.1,1.2 descumm.cpp,1.33,1.34 descumm6.cpp,1.95,1.96
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/tools
In directory sc8-pr-cvs1:/tmp/cvs-serv9509
Modified Files:
descumm.cpp descumm6.cpp
Added Files:
descumm.h
Log Message:
moved some stuff shared by descumm and descumm6 into a new header file: 'descumm.h'
--- NEW FILE: descumm.h ---
/* 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.h,v 1.1 2003/05/10 17:38:44 fingolfin Exp $
*
*/
#ifndef DESCUMM_H
#define DESCUMM_H
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include <io.h>
#include <process.h>
#endif
#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
typedef unsigned char byte;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned int uint;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
uint32 inline SWAP_32(uint32 a)
{
return ((a >> 24) & 0xFF) + ((a >> 8) & 0xFF00) + ((a << 8) & 0xFF0000) +
((a << 24) & 0xFF000000);
}
uint16 inline SWAP_16(uint16 a)
{
return ((a >> 8) & 0xFF) + ((a << 8) & 0xFF00);
}
#if defined(SCUMM_BIG_ENDIAN)
#define TO_BE_32(a) (a)
#define TO_BE_16(a) (a)
#define TO_LE_32(a) SWAP_32(a)
#define TO_LE_16(a) SWAP_16(a)
#else
#define TO_BE_32(a) SWAP_32(a)
#define TO_BE_16(a) SWAP_16(a)
#define TO_LE_32(a) (a)
#define TO_LE_16(a) (a)
#endif
#define MKID(a) (((a&0xff) << 8) | ((a >> 8)&0xff))
//
// The block stack records jump instructions
//
struct BlockStack {
unsigned short from; // From which offset...
unsigned short to; // ...to which offset
bool isWhile; // Set to true if we think this jump is part of a while loop
};
BlockStack *block_stack;
int num_block_stack;
//
// Jump decoding auxillaries (used by the code which tries to translate jumps
// back into if / else / while / etc. constructs).
//
bool pendingElse, haveElse;
int pendingElseTo;
int pendingElseOffs;
int pendingElseOpcode;
int pendingElseIndent;
//
// The opcode of an unconditional jump instruction.
//
int g_jump_opcode;
//
// Command line options
//
bool alwaysShowOffs = false;
bool dontOutputIfs = false;
bool dontOutputElse = false;
bool dontOutputElseif = false;
bool dontOutputWhile = false;
bool dontShowOpcode = false;
bool dontShowOffsets = false;
bool haltOnError;
//
// The SCUMM version used for the script we are descumming.
//
byte scriptVersion;
//
// Various positions / offsets
//
byte *cur_pos, *org_pos;
int offs_of_line;
//
// Total size of the currently loaded script
//
int size_of_code;
#endif
Index: descumm.cpp
===================================================================
RCS file: /cvsroot/scummvm/tools/descumm.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- descumm.cpp 9 May 2003 22:18:18 -0000 1.32
+++ descumm.cpp 10 May 2003 17:38:43 -0000 1.33
@@ -20,16 +20,7 @@
*
*/
-#include <assert.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef WIN32
-#include <io.h>
-#include <process.h>
-#endif
+#include "descumm.h"
/*
Similar to the code that detects "head" while loops like this:
@@ -62,41 +53,6 @@
*/
-#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
-
-typedef unsigned char byte;
-typedef unsigned char uint8;
-typedef unsigned short uint16;
-typedef unsigned int uint32;
-typedef unsigned int uint;
-typedef signed char int8;
-typedef signed short int16;
-typedef signed int int32;
-
-uint32 inline SWAP_32(uint32 a)
-{
- return ((a >> 24) & 0xFF) + ((a >> 8) & 0xFF00) + ((a << 8) & 0xFF0000) +
- ((a << 24) & 0xFF000000);
-}
-
-uint16 inline SWAP_16(uint16 a)
-{
- return ((a >> 8) & 0xFF) + ((a << 8) & 0xFF00);
-}
-
-#if defined(SCUMM_BIG_ENDIAN)
-#define TO_BE_16(x) (x)
-#define TO_BE_32(x) (x)
-#define TO_LE_16(x) SWAP_16(x)
-#define TO_LE_32(x) SWAP_32(x)
-#else
-#define TO_BE_16(x) SWAP_16(x)
-#define TO_BE_32(x) SWAP_32(x)
-#define TO_LE_16(x) (x)
-#define TO_LE_32(x) (x)
-#endif
-
-#define MKID(a) (((a&0xff) << 8) | ((a >> 8)&0xff))
#define A1B (1<<0)
@@ -138,50 +94,22 @@
void get_tok_V2(char *buf); // For V2 (and V1?)
void get_tok(char *buf); // For V3, V4, V5
-const int g_jump_opcode = 0x18;
-
-byte *cur_pos, *org_pos;
-int size_of_code;
-
char *indentbuf;
-struct BlockStack {
- bool isWhile;
- unsigned short from;
- unsigned short to;
-};
-
-
-int num_block_stack;
-BlockStack *block_stack;
-
-bool pendingElse, haveElse;
-int pendingElseTo;
-int pendingElseOffs;
-int pendingElseOpcode;
-int pendingElseIndent;
-
-int offs_of_line;
-
-bool alwaysShowOffs = 0;
-bool dontOutputIfs = 0;
-bool dontOutputWhile = 0;
-bool dontOutputElse = 0;
-bool dontOutputElseif = 0;
-bool dontShowOpcode = 0;
-bool dontShowOffsets = 0;
-bool haltOnError;
-byte scriptVersion = 3;
-
-
int get_curoffs();
-bool IndyFlag = 0;
+bool IndyFlag = false;
bool GF_UNBLOCKED = false;
void emit_if(char *buf, char *condition);
+char *strecpy(char *buf, const char *src)
+{
+ strcpy(buf, src);
+ return strchr(buf, 0);
+}
+
int get_curoffs()
{
return cur_pos - org_pos;
@@ -204,12 +132,6 @@
return (short)get_word();
}
-char *strecpy(char *buf, const char *src)
-{
- strcpy(buf, src);
- return strchr(buf, 0);
-}
-
const char *get_num_string(int i)
{
@@ -3213,14 +3135,15 @@
FILE *in;
byte *mem, *memorg;
int len;
- char *buf; /* token buffer */
- char *filename;
+ char *filename, *buf;
int i;
char *s;
+ scriptVersion = 3;
+ g_jump_opcode = 0x18;
+
+ // Parse the arguments
filename = NULL;
- IndyFlag = 0;
- /* Parse the arguments */
for (i = 1; i < argc; i++) {
s = argv[i];
@@ -3292,7 +3215,6 @@
memorg = mem = (byte *)malloc(65536);
len = fread(mem, 1, 65536, in);
-
fclose(in);
size_of_code = len;
Index: descumm6.cpp
===================================================================
RCS file: /cvsroot/scummvm/tools/descumm6.cpp,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -d -r1.94 -r1.95
--- descumm6.cpp 9 May 2003 00:37:06 -0000 1.94
+++ descumm6.cpp 10 May 2003 17:38:43 -0000 1.95
@@ -20,16 +20,7 @@
*
*/
-#include <assert.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef WIN32
-#include <io.h>
-#include <process.h>
-#endif
+#include "descumm.h"
/*
switch/case statements have a pattern that look as follows (they were probably
@@ -66,41 +57,6 @@
*/
-typedef unsigned char byte;
-typedef unsigned char uint8;
-typedef unsigned short uint16;
-typedef unsigned int uint32;
-typedef unsigned int uint;
-typedef signed char int8;
-typedef signed short int16;
-typedef signed int int32;
-
-uint32 inline SWAP_32(uint32 a)
-{
- return ((a >> 24) & 0xFF) + ((a >> 8) & 0xFF00) + ((a << 8) & 0xFF0000) +
- ((a << 24) & 0xFF000000);
-}
-
-uint16 inline SWAP_16(uint16 a)
-{
- return ((a >> 8) & 0xFF) + ((a << 8) & 0xFF00);
-}
-
-#if defined(SCUMM_BIG_ENDIAN)
-#define TO_BE_32(a) (a)
-#define TO_BE_16(a) (a)
-#define TO_LE_32(a) SWAP_32(a)
-#define TO_LE_16(a) SWAP_16(a)
-#else
-#define TO_BE_32(a) SWAP_32(a)
-#define TO_BE_16(a) SWAP_16(a)
-#define TO_LE_32(a) (a)
-#define TO_LE_16(a) (a)
-#endif
-
-
-
-int g_jump_opcode = 0x66;
struct StackEnt {
byte type;
@@ -162,37 +118,9 @@
StackEnt *stack[128];
int num_stack;
-byte *cur_pos, *org_pos;
char *output;
-bool pendingElse, haveElse;
-int pendingElseTo;
-int pendingElseOffs;
-int pendingElseOpcode;
-int pendingElseIndent;
-
-int offs_of_line;
-
-bool alwaysShowOffs = 0;
-bool dontOutputIfs = 0;
-bool dontOutputElse = 0;
-bool dontOutputElseif = 0;
-bool dontOutputWhile = 0;
-bool dontShowOpcode = 0;
-bool dontShowOffsets = 0;
-bool haltOnError;
-byte scriptVersion = 6;
-
-struct BlockStack {
- bool isWhile;
- unsigned short from;
- unsigned short to;
-};
-
-BlockStack *block_stack;
-int num_block_stack;
-
const char *var_names6[] = {
/* 0 */
NULL,
@@ -1196,7 +1124,7 @@
block_stack = (BlockStack *) malloc(256 * sizeof(BlockStack));
if (num_block_stack >= 256) {
- printf("BlockStack full!\n");
+ printf("block_stack full!\n");
exit(0);
}
return &block_stack[num_block_stack++];
@@ -1279,6 +1207,9 @@
else
k = to - 3;
+ if (k < 0 || k >= size_of_code)
+ return false; /* Invalid jump */
+
if (org_pos[k] != g_jump_opcode)
return false; /* Invalid jump */
@@ -2798,14 +2729,17 @@
int main(int argc, char *argv[])
{
- int i;
- char *s;
- char *filename, *buf;
FILE *in;
byte *mem, *memorg;
int len;
+ char *filename, *buf;
+ int i;
+ char *s;
- /* Parse the arguments */
+ scriptVersion = 6;
+ g_jump_opcode = 0x66;
+
+ // Parse the arguments
filename = NULL;
for (i = 1; i < argc; i++) {
s = argv[i];
@@ -2875,6 +2809,7 @@
memorg = mem = (byte *)malloc(65536);
len = fread(mem, 1, 65536, in);
fclose(in);
+ size_of_code = len;
output = buf = (char *)malloc(8192);
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/scumm gfx.cpp,2.82,2.83 scumm.h,1.180,1.181 scummvm.cpp,2.133,2.134
- Next message: [Scummvm-cvs-logs] CVS: tools descumm-common.cpp,NONE,1.1 descumm.h,1.1,1.2 descumm.cpp,1.33,1.34 descumm6.cpp,1.95,1.96
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list