[Scummvm-cvs-logs] CVS: tools simon1decr.c,NONE,1.1 Makefile,1.15,1.16 Makefile.mingw,1.6,1.7 README,1.3,1.4
Travis Howell
kirben at users.sourceforge.net
Tue May 20 22:14:18 CEST 2003
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/simon items.cpp,1.69,1.70 simon.cpp,1.196,1.197 simon.h,1.63,1.64 vga.cpp,1.48,1.49
- Next message: [Scummvm-cvs-logs] CVS: scummvm README,1.100,1.101
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/tools
In directory sc8-pr-cvs1:/tmp/cvs-serv12838
Modified Files:
Makefile Makefile.mingw README
Added Files:
simon1decr.c
Log Message:
A decruncher for AGA/ECS versions of Simon 1 Amiga from Stuart Caie
--- NEW FILE: simon1decr.c ---
#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.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- Makefile 11 May 2003 22:11:21 -0000 1.15
+++ Makefile 21 May 2003 05:13:22 -0000 1.16
@@ -13,6 +13,7 @@
descumm6$(EXEEXT) \
extract$(EXEEXT) \
rescumm$(EXEEXT) \
+ simon1decr$(EXEEXT) \
simon2mp3$(EXEEXT)
all: $(TARGETS)
@@ -27,6 +28,9 @@
$(CC) $(LFLAGS) -o $@ $+
rescumm$(EXEEXT): rescumm.o
+ $(CC) $(LFLAGS) -o $@ $+
+
+simon1decr$(EXEEXT): simon1decr.o
$(CC) $(LFLAGS) -o $@ $+
simon2mp3$(EXEEXT): simon2mp3.o
Index: Makefile.mingw
===================================================================
RCS file: /cvsroot/scummvm/tools/Makefile.mingw,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Makefile.mingw 4 May 2003 14:05:44 -0000 1.6
+++ Makefile.mingw 21 May 2003 05:13:22 -0000 1.7
@@ -12,6 +12,7 @@
strip descumm6.exe -o $(SCUMMVMPATH)/tools/descumm6.exe
strip extract.exe -o $(SCUMMVMPATH)/tools/extract.exe
strip rescumm.exe -o $(SCUMMVMPATH)/tools/rescumm.exe
+ strip simon1decr.exe -o $(SCUMMVMPATH)/tools/simon1decr.exe
strip simon2mp3.exe -o $(SCUMMVMPATH)/tools/simon2mp3.exe
cp COPYING $(SCUMMVMPATH)/tools/copying.txt
cp README $(SCUMMVMPATH)/tools/readme.txt
Index: README
===================================================================
RCS file: /cvsroot/scummvm/tools/README,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- README 4 May 2003 14:07:59 -0000 1.3
+++ README 21 May 2003 05:13:22 -0000 1.4
@@ -16,5 +16,8 @@
(When decompiling V7 'room-' scripts, you may need to
use the -7 switch; likewise for V8 you need -8)
+ simon1decr - Used to decrunch the main graphics files in AGA/ECS
+ versions of Simon the Sorcerer 1 for Amiga
+
simon2mp3 - Used to MP3 compress .voc or .wav files to .mp3, for
use with ScummVMs -DUSE_MAD support. Requires MAD
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/simon items.cpp,1.69,1.70 simon.cpp,1.196,1.197 simon.h,1.63,1.64 vga.cpp,1.48,1.49
- Next message: [Scummvm-cvs-logs] CVS: scummvm README,1.100,1.101
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list