/* uncomp.c - uncompresses ROM files from WAC .exe files */ /* Version 1.0 1-JAN-96 */ /* Copyright © 1996 Sean Riddle */ /* Freely distributable on any medium given all copyrights are retained */ /* by the author and no charge greater than $7.00 is made for obtaining */ /* this software */ /* Please send all bug reports and update ideas to: */ /* seanriddle <at> airosurf <dot> com */ /* latest version at: */ /* http://www.seanriddle.com */ /* usage: uncomp <file> [VERBOSE] */ /* VERBOSE prints additional info */ /* NOTE: doesn't yet work with DEFENDER.EXE */ /* compiled on Amiga SAS/C 6.56 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #define FALSE 0 #define TRUE 1 void main(int argc,char *argv[]) { FILE *fp; struct stat st; unsigned char *buf,*out; int i,j; int copy,rep; unsigned char data,x; char ex=FALSE; char verbose=FALSE; int bytes=0; char sin=FALSE; char outfile[256]; if((argc>1)&&(argc<4)) { for(i=1;i<argc;i++) { if(!stricmp(argv[i],"verbose")) verbose=TRUE; } if(!stat(argv[1],&st)) { if(buf=(UBYTE *)malloc(st.st_size+65536)) { out=buf+st.st_size; for(i=0;i<65536;i++) out[i]=0xff; if(fp=fopen(argv[1],"rb")) { if(fread(buf,st.st_size,1,fp)) { if(st.st_size>0x16ad5) if(buf[0x16ad5]==0xb2) sin=TRUE; if(verbose) printf("!!!buf=%x, out=%x\n",buf,out); if(verbose) if(sin) printf("Sinistar!\n"); i=st.st_size-1; j=65535; while(i&&(!((buf[i]==0x40)&&(buf[i+1]==0x00)))) i--; while(i&&(!(((buf[i]==0xb2)||(buf[i]==0xb0))&& (buf[i+1]==0xff)))) i--; x=buf[i--]; if(verbose) printf("!!!found %X, i=%d\n",x,i); while(!ex&&(i>=0)) { if(j<0) { printf("Writing 65536 bytes: "); ex=TRUE; } else { if(x==0xb2) { copy=(buf[i--]<<8)+buf[i--]; bytes+=copy; if(verbose) printf("!!!copy=%d\n",copy); while(!ex&&(copy--)) out[j--]=buf[i--]; if((x=buf[i--])!=0xb0) { if(verbose) printf("!!!no b0 at %d (%d)\n",i,x); ex=TRUE; } if(sin&&((j<=0xDFFF)&&(j>=0xD000))) { if(verbose) printf("!!!skipping Sinistar SRAM area\n"); j=0xcfff; } if((j<=0xcc00)&&(j>=0xA000)) { if(verbose) printf("!!!skipping RAM and I/O areas\n"); j=0x8fff; } } while(!ex&&(x==0xb0)) { rep=(buf[i--]<<8)+buf[i--]; bytes+=rep; if(verbose) printf("!!!rep=%d\n",rep); data=buf[i--]; if(verbose) printf("!!!data=%d\n",data); x=buf[i--]; while(rep--) out[j--]=data; } if(x!=0xb2) { printf("bytes=%d\n",bytes); printf("!!!no b2 at %d (%d)\n",i,x); ex=TRUE; } } } strcpy(outfile,argv[1]); if(!stricmp(&outfile[strlen(outfile)-4],".EXE")) outfile[strlen(outfile)-4]=NULL; strcat(outfile,".rom"); if(fp=fopen(outfile,"wb")) { printf("`%s'\n",outfile); fwrite(out,65536,1,fp); fclose(fp); } else printf("Can't open `ram:willyrom'\n"); } else printf("couldn't read `%s'\n",argv[1]); fclose(fp); } else printf("can't open `%s'\n",argv[1]); free(buf); } else printf("no mem\n"); } else printf("can't stat `%s'\n",argv[1]); } else printf("Usage: `%s <file> [VERBOSE]'\n",argv[0]); }
Satoremihi7