[Scummvm-cvs-logs] CVS: tools extract_simon1_amiga.c,NONE,1.1 Makefile,1.46,1.47 Makefile.mingw,1.25,1.26 README,1.32,1.33 simon1decr.c,1.5,NONE

Travis Howell kirben at users.sourceforge.net
Thu Dec 23 18:46:01 CET 2004


Update of /cvsroot/scummvm/tools
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13736

Modified Files:
	Makefile Makefile.mingw README 
Added Files:
	extract_simon1_amiga.c 
Removed Files:
	simon1decr.c 
Log Message:

Rename simon1decr to match others.


--- NEW FILE: extract_simon1_amiga.c ---
/* Simon1Decr - Extracts Simon the Sorcerer 1 Amiga (AGA/ECS) graphics or music files
 * Copyright (C) 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/extract_simon1_amiga.c,v 1.1 2004/12/24 02:44:55 kirben Exp $
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

typedef unsigned int ULONG;
typedef unsigned char UBYTE;

#define EndGetM32(a)  ((((a)[0])<<24)|(((a)[1])<<16)|(((a)[2])<<8)|((a)[3]))

#define SD_GETBIT(var) do { \
  if (!bits--) { s -= 4; if (s < src) return 0; bb=EndGetM32(s); bits=31; } \
  (var) = bb & 1; bb >>= 1; \
} while (0)

#define SD_GETBITS(var, nbits) do { \
  bc=(nbits); (var)=0; while (bc--) {(var)<<=1; SD_GETBIT(bit); (var)|=bit; } \
} while (0)

#define SD_TYPE_LITERAL (0)
#define SD_TYPE_MATCH   (1)

int simon_decr(UBYTE *src, UBYTE *dest, ULONG srclen) {
  UBYTE *s = &src[srclen - 4];
  ULONG destlen = EndGetM32(s), bb, x, y;
  UBYTE *d = &dest[destlen], bc, bit, bits, type;

  /* initialise bit buffer */
  s -= 4; x = EndGetM32(s); bb = x;
  bits = 0; do { x >>= 1; bits++; } while (x); bits--;

  while (d > dest) {
    SD_GETBIT(x);
    if (x) {
      SD_GETBITS(x, 2);
           if (x == 0) { type = SD_TYPE_MATCH;   x = 9;  y = 2;            }
      else if (x == 1) { type = SD_TYPE_MATCH;   x = 10; y = 3;            }
      else if (x == 2) { type = SD_TYPE_MATCH;   x = 12; SD_GETBITS(y, 8); }
      else             { type = SD_TYPE_LITERAL; x = 8;  y = 8;            }
    }
    else {
      SD_GETBIT(x);
      if (x)           { type = SD_TYPE_MATCH;   x = 8;  y = 1;            }
      else             { type = SD_TYPE_LITERAL; x = 3;  y = 0;            }
    }

    if (type == SD_TYPE_LITERAL) {
      SD_GETBITS(x, x); y += x;
      if ((y + 1) > (d - dest)) return 0; /* overflow? */
      do { SD_GETBITS(x, 8); *--d = x; } while (y-- > 0);
    }
    else {
      if ((y + 1) > (d - dest)) return 0; /* overflow? */
      SD_GETBITS(x, x);
      if ((d + x) > (dest + destlen)) return 0; /* offset overflow? */
      do { d--; *d = d[x]; } while (y-- > 0);
    }
  }
  /* successful decrunch */
  return 1;
}

ULONG simon_decr_length(UBYTE *src, ULONG srclen) {
  return EndGetM32(&src[srclen - 4]);
}


/* - loadfile(filename) loads a file from disk, and returns a pointer to that
 *   loaded file, or returns NULL on failure
 * - call free() on ptr to free memory
 * - size of loaded file is available in global var 'filelen'
 */
size_t filelen;
void *loadfile(char *name) {
  void *mem = NULL; FILE *fd;
  if ((fd = fopen(name, "rb"))) {
    if ((fseek(fd, 0, SEEK_END) == 0) && (filelen = ftell(fd))
    &&  (fseek(fd, 0, SEEK_SET) == 0) && (mem = malloc(filelen))) {
      if (fread(mem, 1, filelen, fd) < filelen) { free(mem); mem = NULL; }
    }
    fclose(fd);
  }
  return mem;
}

/* - savefile(filename, mem, length) saves [length] bytes from [mem] into
 *   the file named by [filename]
 * - returns zero if failed, or non-zero if successful
 */
int savefile(char *name, void *mem, size_t length) {
  FILE *fd = fopen(name, "wb");
  int ok = fd && (fwrite(mem, 1, length, fd) == length);
  if (fd) fclose(fd);
  return ok;
}

char filename[256];

int main(int argc, char *argv[]) {
  for (argv++; *argv; argv++) {
    UBYTE *x = (UBYTE *) loadfile(*argv);
    if (x) {
      ULONG decrlen = simon_decr_length(x, (ULONG) filelen);
      UBYTE *out = (UBYTE *) malloc(decrlen);
      if (out) {
        if (simon_decr(x, out, filelen)) {
          strcpy(filename, *argv);
          strcat(filename, ".out");
          savefile(filename, out, decrlen);
        }
        else {
          printf("%s: decrunch error\n", filename);
        }
        free((void *) x);
      }
    }
  }
  return 0;
}

Index: Makefile
===================================================================
RCS file: /cvsroot/scummvm/tools/Makefile,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- Makefile	24 Dec 2004 02:10:20 -0000	1.46
+++ Makefile	24 Dec 2004 02:44:55 -0000	1.47
@@ -30,7 +30,7 @@
 	extract_loom_tg16$(EXEEXT) \
 	extract_mm_nes$(EXEEXT) \
 	extract_scumm_mac$(EXEEXT) \
-	simon1decr$(EXEEXT)
+	extract_simon1_amiga$(EXEEXT)
 
 all: $(TARGETS)
 
@@ -67,7 +67,7 @@
 compress_saga$(EXEEXT): compress_saga.o compress.o util.o
 	$(CC) $(LDFLAGS) -o $@ $+
 
-simon1decr$(EXEEXT): simon1decr.o
+extract_simon1_amiga$(EXEEXT): extract_simon1_amiga.o
 	$(CC) $(LDFLAGS) -o $@ $+
 
 compress_simon$(EXEEXT): compress_simon.o compress.o util.o

Index: Makefile.mingw
===================================================================
RCS file: /cvsroot/scummvm/tools/Makefile.mingw,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- Makefile.mingw	24 Dec 2004 02:10:20 -0000	1.25
+++ Makefile.mingw	24 Dec 2004 02:44:55 -0000	1.26
@@ -22,7 +22,7 @@
 	strip extract_loom_tg16.exe -o $(SCUMMVMPATH)/tools/extract_loom_tg16.exe
 	strip extract_mm_nes.exe -o $(SCUMMVMPATH)/tools/extract_mm_nes.exe
 	strip extract_scumm_mac.exe -o $(SCUMMVMPATH)/tools/extract_scumm_mac.exe
-	strip simon1decr.exe -o $(SCUMMVMPATH)/tools/simon1decr.exe
+	strip extract_simon1_amiga.exe -o $(SCUMMVMPATH)/tools/extract_simon1_amiga.exe
 	cp COPYING $(SCUMMVMPATH)/tools/copying.txt
 	cp README $(SCUMMVMPATH)/tools/readme.txt
 	u2d $(SCUMMVMPATH)/tools/*.txt

Index: README
===================================================================
RCS file: /cvsroot/scummvm/tools/README,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- README	24 Dec 2004 02:10:20 -0000	1.32
+++ README	24 Dec 2004 02:44:55 -0000	1.33
@@ -25,6 +25,10 @@
                 Extracts data files from NES version of Maniac Mansion.
                 There is currently no support for this game in ScummVM!
 
+        extract_simon1_amiga
+                Extracts the graphics or music files in AGA/ECS
+                versions of Simon the Sorcerer 1 for Amiga
+
 Compression Tools:
         compress_scumm_sou 
                 Used to compress .sou files to .so3 (MP3), .sog (Vorbis),
@@ -78,8 +82,3 @@
 
         dekyra
                 Basic script disassembler for Legend of Kyrandia games
-
-Other tools:
-        simon1decr
-                Used to decrunch the graphics and music files in AGA/ECS 
-                versions of Simon the Sorcerer 1 for Amiga 

--- simon1decr.c DELETED ---





More information about the Scummvm-git-logs mailing list